summaryrefslogtreecommitdiff
path: root/auto_tests/TCP_test.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-08-09 23:53:39 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-08-16 21:01:38 +0000
commit54066f338f185f2fbd6694d9a4877f42cbfa21c8 (patch)
treee056e50af1009bf373c040812e46cd1de8de9979 /auto_tests/TCP_test.c
parent31ea1aa06e59d24d5196b17be9a7105d85c25080 (diff)
Reduce the number of times `unix_time_update` is called.
Reduced by, e.g.: * `file_transfer_test`: 33% of the `clock_gettime` calls. * `tox_many_test`: 53% of the `clock_gettime` calls. Other tests will see similar improvements. Real world applications will be closer to 40-50% improvement, since tox_many_test has 100 nodes, while file_transfer_test has 2 nodes.
Diffstat (limited to 'auto_tests/TCP_test.c')
-rw-r--r--auto_tests/TCP_test.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c
index 07266543..52ecad77 100644
--- a/auto_tests/TCP_test.c
+++ b/auto_tests/TCP_test.c
@@ -39,6 +39,7 @@ static inline IP get_loopback()
39static void do_TCP_server_delay(TCP_Server *tcp_s, int delay) 39static void do_TCP_server_delay(TCP_Server *tcp_s, int delay)
40{ 40{
41 c_sleep(delay); 41 c_sleep(delay);
42 unix_time_update();
42 do_TCP_server(tcp_s); 43 do_TCP_server(tcp_s);
43 c_sleep(delay); 44 c_sleep(delay);
44} 45}
@@ -141,6 +142,7 @@ START_TEST(test_basic)
141 i += msg_length; 142 i += msg_length;
142 143
143 c_sleep(50); 144 c_sleep(50);
145 unix_time_update();
144 do_TCP_server(tcp_s); 146 do_TCP_server(tcp_s);
145 } 147 }
146 148
@@ -477,6 +479,7 @@ START_TEST(test_client)
477 const uint8_t LOOP_SIZE = 3; 479 const uint8_t LOOP_SIZE = 3;
478 480
479 for (uint8_t i = 0; i < LOOP_SIZE; i++) { 481 for (uint8_t i = 0; i < LOOP_SIZE; i++) {
482 unix_time_update();
480 do_TCP_connection(conn, nullptr); // Run the connection loop. 483 do_TCP_connection(conn, nullptr); // Run the connection loop.
481 484
482 // The status of the connection should continue to be TCP_CLIENT_CONFIRMED after multiple subsequent do_TCP_connection() calls. 485 // The status of the connection should continue to be TCP_CLIENT_CONFIRMED after multiple subsequent do_TCP_connection() calls.
@@ -584,6 +587,7 @@ START_TEST(test_client_invalid)
584 TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, nullptr); 587 TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, nullptr);
585 588
586 // Run the client's main loop but not the server. 589 // Run the client's main loop but not the server.
590 unix_time_update();
587 do_TCP_connection(conn, nullptr); 591 do_TCP_connection(conn, nullptr);
588 c_sleep(50); 592 c_sleep(50);
589 593
@@ -592,11 +596,13 @@ START_TEST(test_client_invalid)
592 TCP_CLIENT_CONNECTING, tcp_con_status(conn)); 596 TCP_CLIENT_CONNECTING, tcp_con_status(conn));
593 // After 5s... 597 // After 5s...
594 c_sleep(5000); 598 c_sleep(5000);
599 unix_time_update();
595 do_TCP_connection(conn, nullptr); 600 do_TCP_connection(conn, nullptr);
596 ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %d, is: %d.", 601 ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %d, is: %d.",
597 TCP_CLIENT_CONNECTING, tcp_con_status(conn)); 602 TCP_CLIENT_CONNECTING, tcp_con_status(conn));
598 // 11s... (Should wait for 10 before giving up.) 603 // 11s... (Should wait for 10 before giving up.)
599 c_sleep(6000); 604 c_sleep(6000);
605 unix_time_update();
600 do_TCP_connection(conn, nullptr); 606 do_TCP_connection(conn, nullptr);
601 ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_DISCONNECTED, "Wrong status. Expected: %d, is: %d.", 607 ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_DISCONNECTED, "Wrong status. Expected: %d, is: %d.",
602 TCP_CLIENT_DISCONNECTED, tcp_con_status(conn)); 608 TCP_CLIENT_DISCONNECTED, tcp_con_status(conn));