test(chat): cancel avatar peers from the committed receive callback
This commit is contained in:
1 parent
65409f8c80
commit
e8b913a351
1 file changed
+13
@@ -12,6 +12,7 @@ static struct UASYNC* ua;
|
||||
static unsigned received_blocks;
|
||||
static uint64_t old_version;
|
||||
static int capture_blocks;
|
||||
static int cancel_on_update;
|
||||
static uint8_t group_private[32], group_public[32], group_x[32];
|
||||
|
||||
static void hex(const uint8_t* input, char* out) { for (unsigned i = 0; i < 32; i++) snprintf(out + i * 2, 3, "%02x", input[i]); }
|
||||
@@ -25,6 +26,13 @@ static void capture(int level, const char* category, const char* message) {
|
||||
struct group_avatar_record current; assert(!group_avatar_get(nodes[1], GROUP, ¤t));
|
||||
assert(current.version == old_version); // Даже последний блок ещё не опубликован до проверки всей записи.
|
||||
}
|
||||
static void cancel_received_avatar(struct UTUN_INSTANCE* inst, int type, const uint8_t* data, int size) {
|
||||
(void)data; (void)size;
|
||||
if (type != CHAT_EVT_CHANNEL_UPDATED || !cancel_on_update) return;
|
||||
assert(inst == nodes[1] && sqlite3_get_autocommit(inst->topo_sqlite_db));
|
||||
cancel_on_update = 0; group_avatar_cancel_group(inst, GROUP);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CHAT, "test group avatar: cancelled all peer tasks from committed receive event");
|
||||
}
|
||||
static void put_member(unsigned destination, unsigned member) {
|
||||
uint8_t join[64], tree[64], message[512];
|
||||
int n = member_sync_build_join_msg(group_x, group_public, nodes[member]->node_id,
|
||||
@@ -163,6 +171,11 @@ int main(void) {
|
||||
assert(sc_ed25519_sign(group_private, signed_bytes, ga_message(GROUP, ©, signed_bytes), copy.signature) == SC_OK);
|
||||
int accepted = ga_compare(copy.version, copy.hash, next.version, next.hash) > 0;
|
||||
assert(group_avatar_apply(nodes[0], GROUP, ©) == accepted);
|
||||
// Событие вправе удалить peer-контекст: приём не обращается к нему после callback.
|
||||
chat_event_set_handler(nodes[1], cancel_received_avatar); cancel_on_update = 1;
|
||||
image[1] ^= 1; assert(!group_avatar_set(nodes[0], GROUP, image, 17));
|
||||
assert(!group_avatar_get(nodes[0], GROUP, &next) && wait_record(1, next.version, next.hash) && !cancel_on_update);
|
||||
chat_event_set_handler(nodes[1], NULL);
|
||||
assert(!group_avatar_set(nodes[0], GROUP, NULL, 0)); assert(!group_avatar_get(nodes[0], GROUP, &next));
|
||||
assert(wait_record(1, next.version, next.hash)); assert(!group_avatar_get(nodes[1], GROUP, ©) && !copy.size);
|
||||
assert(group_avatar_apply(nodes[1], GROUP, &first) == 0);
|
||||
|
||||
Reference in new issue
Block a user