summaryrefslogtreecommitdiff
path: root/auto_tests/reconnect_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'auto_tests/reconnect_test.c')
-rw-r--r--auto_tests/reconnect_test.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/auto_tests/reconnect_test.c b/auto_tests/reconnect_test.c
index 76cabd17..e56d818c 100644
--- a/auto_tests/reconnect_test.c
+++ b/auto_tests/reconnect_test.c
@@ -24,6 +24,7 @@
24 24
25typedef struct State { 25typedef struct State {
26 uint32_t index; 26 uint32_t index;
27 uint64_t clock;
27} State; 28} State;
28 29
29#include "run_auto_test.h" 30#include "run_auto_test.h"
@@ -64,9 +65,7 @@ static void test_reconnect(Tox **toxes, State *state)
64 printf("letting connections settle\n"); 65 printf("letting connections settle\n");
65 66
66 do { 67 do {
67 iterate_all(TOX_COUNT, toxes, state); 68 iterate_all_wait(TOX_COUNT, toxes, state, ITERATION_INTERVAL);
68
69 c_sleep(ITERATION_INTERVAL);
70 } while (time(nullptr) - test_start_time < 2); 69 } while (time(nullptr) - test_start_time < 2);
71 70
72 uint16_t disconnect = random_u16() % TOX_COUNT; 71 uint16_t disconnect = random_u16() % TOX_COUNT;
@@ -76,25 +75,24 @@ static void test_reconnect(Tox **toxes, State *state)
76 for (uint16_t i = 0; i < TOX_COUNT; ++i) { 75 for (uint16_t i = 0; i < TOX_COUNT; ++i) {
77 if (i != disconnect) { 76 if (i != disconnect) {
78 tox_iterate(toxes[i], &state[i]); 77 tox_iterate(toxes[i], &state[i]);
78 state[i].clock += 1000;
79 } 79 }
80 } 80 }
81 81
82 c_sleep(ITERATION_INTERVAL); 82 c_sleep(20);
83 } while (!all_disconnected_from(TOX_COUNT, toxes, state, disconnect)); 83 } while (!all_disconnected_from(TOX_COUNT, toxes, state, disconnect));
84 84
85 const time_t reconnect_start_time = time(nullptr); 85 const uint64_t reconnect_start_time = state[0].clock;
86 86
87 printf("reconnecting\n"); 87 printf("reconnecting\n");
88 88
89 do { 89 do {
90 iterate_all(TOX_COUNT, toxes, state); 90 iterate_all_wait(TOX_COUNT, toxes, state, ITERATION_INTERVAL);
91
92 c_sleep(ITERATION_INTERVAL);
93 } while (!all_friends_connected(TOX_COUNT, toxes)); 91 } while (!all_friends_connected(TOX_COUNT, toxes));
94 92
95 const int reconnect_time = (int)(time(nullptr) - reconnect_start_time); 93 const uint64_t reconnect_time = state[0].clock - reconnect_start_time;
96 ck_assert_msg(reconnect_time <= RECONNECT_TIME_MAX, "reconnection took %d seconds; expected at most %d seconds", 94 ck_assert_msg(reconnect_time <= RECONNECT_TIME_MAX * 1000, "reconnection took %d seconds; expected at most %d seconds",
97 reconnect_time, RECONNECT_TIME_MAX); 95 (int)(reconnect_time / 1000), RECONNECT_TIME_MAX);
98 96
99 printf("test_reconnect succeeded, took %d seconds\n", (int)(time(nullptr) - test_start_time)); 97 printf("test_reconnect succeeded, took %d seconds\n", (int)(time(nullptr) - test_start_time));
100} 98}