|
|
|
|
@ -20,6 +20,7 @@
|
|
|
|
|
#include "../src/transport_layer/secure_channel.h" |
|
|
|
|
#include "../src/transport_layer/etcp.h" |
|
|
|
|
#include "test_utils.h" |
|
|
|
|
#include "test_clock.h" |
|
|
|
|
|
|
|
|
|
static struct UTUN_INSTANCE* nodes[2]; |
|
|
|
|
static int results[16], calls[16], joined; |
|
|
|
|
@ -97,7 +98,7 @@ static void request(uint64_t id, uint64_t group, const char* source, int cancel)
|
|
|
|
|
|
|
|
|
|
static int wait_result(struct UASYNC* ua, int id, int expected) { |
|
|
|
|
uint64_t deadline = get_time_tb() + 30000; |
|
|
|
|
while (!calls[id] && get_time_tb() < deadline) uasync_poll(ua, 100); |
|
|
|
|
while (!calls[id] && get_time_tb() < deadline) test_clock_poll(ua, 100); |
|
|
|
|
return calls[id] == 1 && results[id] == expected; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -110,7 +111,7 @@ static int join_link(struct UASYNC* ua, const char* link) {
|
|
|
|
|
chat_sync_connect_from_invite(nodes[1], invite.channelId, invite.nodeId, invite.pubkey, |
|
|
|
|
addresses, invite.addrCount, bytes, NULL, invite.join_key); |
|
|
|
|
uint64_t deadline = get_time_tb() + 200000; |
|
|
|
|
while (!joined && get_time_tb() < deadline) uasync_poll(ua, 100); |
|
|
|
|
while (!joined && get_time_tb() < deadline) test_clock_poll(ua, 100); |
|
|
|
|
if (joined != 1) { DEBUG_ERROR(DEBUG_CATEGORY_DM, "invite test: JOIN failed ch=%llu result=%d", |
|
|
|
|
(unsigned long long)joining_channel, joined); return -1; } |
|
|
|
|
return 0; |
|
|
|
|
@ -146,6 +147,7 @@ static int start_node(struct UASYNC* ua, const char* directory, int index, int p
|
|
|
|
|
|
|
|
|
|
int main(void) { |
|
|
|
|
debug_config_init(); debug_set_level(DEBUG_LEVEL_ERROR); |
|
|
|
|
test_clock_init(1000); test_clock_sync_wall_time(); |
|
|
|
|
if (getenv("UTUN_TEST_DEBUG")) { |
|
|
|
|
debug_set_category_level(DEBUG_CATEGORY_DM, DEBUG_LEVEL_DEBUG); |
|
|
|
|
debug_set_category_level(DEBUG_CATEGORY_CHAT_SYNC, DEBUG_LEVEL_DEBUG); |
|
|
|
|
@ -167,7 +169,7 @@ int main(void) {
|
|
|
|
|
struct link_result first = {0}; |
|
|
|
|
CHECK(chat_invite_build_link(nodes[0], source, 0, NULL, link_ready, &first), "build initial invite"); |
|
|
|
|
uint64_t deadline = get_time_tb() + 30000; |
|
|
|
|
while (!first.ready && get_time_tb() < deadline) uasync_poll(ua, 100); |
|
|
|
|
while (!first.ready && get_time_tb() < deadline) test_clock_poll(ua, 100); |
|
|
|
|
CHECK(first.ready == 1 && !join_link(ua, first.link), "join common source group"); |
|
|
|
|
chat_core_create_channel_auto(nodes[0], "target \"группа\"\n<>&"); |
|
|
|
|
CHECK(!scalar(nodes[0], "SELECT channel_id FROM channels WHERE name='target \"группа\"\n<>&'", &target), |
|
|
|
|
@ -212,7 +214,7 @@ int main(void) {
|
|
|
|
|
deadline = get_time_tb() + 100000; |
|
|
|
|
char* link = NULL; |
|
|
|
|
do { |
|
|
|
|
uasync_poll(ua, 100); |
|
|
|
|
test_clock_poll(ua, 100); |
|
|
|
|
if (!dm_list_messages_json(nodes[1], conv, 10, 0, messages, sizeof(messages), &length)) link = strstr(messages, "utun://"); |
|
|
|
|
} while (!link && get_time_tb() < deadline); |
|
|
|
|
CHECK(link, "invite delivered to B over source group's UDP route"); |
|
|
|
|
@ -240,14 +242,14 @@ int main(void) {
|
|
|
|
|
chat_core_connect_channel(nodes[1], target_id); |
|
|
|
|
deadline = get_time_tb() + 100000; |
|
|
|
|
while (!topo_node_sqlite_member_in_channel(nodes[1]->topo_sqlite_db, target_id, nodes[1]->node_id) && |
|
|
|
|
get_time_tb() < deadline) uasync_poll(ua, 100); |
|
|
|
|
get_time_tb() < deadline) test_clock_poll(ua, 100); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_DM, "invite test: membership after JOIN ch=%s A_has_B=%d B_has_B=%d", target_id, |
|
|
|
|
topo_node_sqlite_member_in_channel(nodes[0]->topo_sqlite_db, target_id, nodes[1]->node_id), |
|
|
|
|
topo_node_sqlite_member_in_channel(nodes[1]->topo_sqlite_db, target_id, nodes[1]->node_id)); |
|
|
|
|
CHECK(topo_node_sqlite_member_in_channel(nodes[0]->topo_sqlite_db, target_id, nodes[1]->node_id) && |
|
|
|
|
topo_node_sqlite_member_in_channel(nodes[1]->topo_sqlite_db, target_id, nodes[1]->node_id), "membership committed on both nodes"); |
|
|
|
|
deadline = get_time_tb() + 400000; |
|
|
|
|
while (chat_core_count(nodes[1], target_id) != 5 && get_time_tb() < deadline) uasync_poll(ua, 100); |
|
|
|
|
while (chat_core_count(nodes[1], target_id) != 5 && get_time_tb() < deadline) test_clock_poll(ua, 100); |
|
|
|
|
CHECK(chat_core_count(nodes[1], target_id) == 5, "history created before invitation arrives after JOIN"); |
|
|
|
|
CHECK(!getenv("UTUN_TEST_HISTORY_TIMEOUT") || dropped_requests == 2, "requester retries after lost initial exchange"); |
|
|
|
|
CHECK(!chat_core_get_messages_json(nodes[1], target_id, 10, 0, messages, sizeof(messages), &length), "read received history"); |
|
|
|
|
@ -276,7 +278,7 @@ int main(void) {
|
|
|
|
|
chat_core_submit_message(nodes[0], &offline); |
|
|
|
|
CHECK(!topo_group_new_conn(target_group, shared_conn), "restart target session on shared transport"); |
|
|
|
|
deadline = get_time_tb() + 100000; |
|
|
|
|
while (chat_core_count(nodes[1], target_id) != 6 && get_time_tb() < deadline) uasync_poll(ua, 100); |
|
|
|
|
while (chat_core_count(nodes[1], target_id) != 6 && get_time_tb() < deadline) test_clock_poll(ua, 100); |
|
|
|
|
CHECK(ready_events == 1 && chat_core_count(nodes[1], target_id) == 6 && |
|
|
|
|
!chat_core_get_messages_json(nodes[1], target_id, 10, 0, messages, sizeof(messages), &length) && strstr(messages, missed), |
|
|
|
|
"new READY session resumes history and receives the missed message"); |
|
|
|
|
@ -288,7 +290,7 @@ int main(void) {
|
|
|
|
|
message.data = (uint8_t*)text; message.data_len = (uint32_t)strlen(text); |
|
|
|
|
chat_core_submit_message(nodes[1], &message); |
|
|
|
|
deadline = get_time_tb() + 100000; |
|
|
|
|
while (chat_core_count(nodes[0], target_id) != 7 && get_time_tb() < deadline) uasync_poll(ua, 100); |
|
|
|
|
while (chat_core_count(nodes[0], target_id) != 7 && get_time_tb() < deadline) test_clock_poll(ua, 100); |
|
|
|
|
CHECK(!chat_core_get_messages_json(nodes[0], target_id, 10, 0, messages, sizeof(messages), &length) && strstr(messages, text), |
|
|
|
|
"joined client can send a group message to the inviter"); |
|
|
|
|
request(6, target, "", 0); |
|
|
|
|
@ -298,6 +300,7 @@ int main(void) {
|
|
|
|
|
done: |
|
|
|
|
for (int i = 0; i < 2; i++) if (nodes[i]) utun_instance_destroy(nodes[i]); |
|
|
|
|
if (ua) uasync_destroy(ua, 0); |
|
|
|
|
test_clock_finish(); |
|
|
|
|
printf("PM invite: cancellation, failure, delivery and JOIN: %s\n", failed ? "FAIL" : "OK"); |
|
|
|
|
return failed; |
|
|
|
|
} |
|
|
|
|
|