From ac3e8fea633d590778dd42d865afe4a7d574e59b Mon Sep 17 00:00:00 2001 From: iphydf Date: Sun, 27 Mar 2022 13:52:03 +0000 Subject: [PATCH] test: Improve stability of tox_many_tcp_test. If the TCP port is in use, try the next TCP port. --- auto_tests/tox_many_tcp_test.c | 23 +++++++++++-------- .../docker/tox-bootstrapd.sha256 | 2 +- toxcore/TCP_server.c | 4 ++-- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/auto_tests/tox_many_tcp_test.c b/auto_tests/tox_many_tcp_test.c index 39b25de0..b406bc83 100644 --- a/auto_tests/tox_many_tcp_test.c +++ b/auto_tests/tox_many_tcp_test.c @@ -37,10 +37,7 @@ static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8 #define NUM_FRIENDS 50 #define NUM_TOXES_TCP 40 -#ifdef TCP_RELAY_PORT -#undef TCP_RELAY_PORT -#endif -#define TCP_RELAY_PORT 33448 +static uint16_t tcp_relay_port = 33448; static void test_many_clients_tcp(void) { @@ -54,19 +51,27 @@ static void test_many_clients_tcp(void) struct Tox_Options *opts = tox_options_new(nullptr); if (i == 0) { - tox_options_set_tcp_port(opts, TCP_RELAY_PORT); + tox_options_set_tcp_port(opts, tcp_relay_port); } else { tox_options_set_udp_enabled(opts, false); } index[i] = i + 1; - toxes[i] = tox_new_log(opts, nullptr, &index[i]); + Tox_Err_New err; + toxes[i] = tox_new_log(opts, &err, &index[i]); + if (i == 0 && err == TOX_ERR_NEW_PORT_ALLOC) { + ck_assert(toxes[i] == nullptr); + --i; + ++tcp_relay_port; + tox_options_free(opts); + continue; + } ck_assert_msg(toxes[i] != nullptr, "Failed to create tox instances %u", i); tox_callback_friend_request(toxes[i], accept_friend_request); uint8_t dpk[TOX_PUBLIC_KEY_SIZE]; tox_self_get_dht_id(toxes[0], dpk); Tox_Err_Bootstrap error = TOX_ERR_BOOTSTRAP_OK; - ck_assert_msg(tox_add_tcp_relay(toxes[i], TOX_LOCALHOST, TCP_RELAY_PORT, dpk, &error), "add relay error, %u, %d", i, + ck_assert_msg(tox_add_tcp_relay(toxes[i], TOX_LOCALHOST, tcp_relay_port, dpk, &error), "add relay error, %u, %d", i, error); uint16_t first_port = tox_self_get_udp_port(toxes[0], nullptr); ck_assert_msg(tox_bootstrap(toxes[i], TOX_LOCALHOST, first_port, dpk, nullptr), "Bootstrap error"); @@ -147,7 +152,7 @@ static void test_many_clients_tcp_b(void) struct Tox_Options *opts = tox_options_new(nullptr); if (i < NUM_TCP_RELAYS) { - tox_options_set_tcp_port(opts, TCP_RELAY_PORT + i); + tox_options_set_tcp_port(opts, tcp_relay_port + i); } else { tox_options_set_udp_enabled(opts, 0); } @@ -158,7 +163,7 @@ static void test_many_clients_tcp_b(void) tox_callback_friend_request(toxes[i], accept_friend_request); uint8_t dpk[TOX_PUBLIC_KEY_SIZE]; tox_self_get_dht_id(toxes[(i % NUM_TCP_RELAYS)], dpk); - ck_assert_msg(tox_add_tcp_relay(toxes[i], TOX_LOCALHOST, TCP_RELAY_PORT + (i % NUM_TCP_RELAYS), dpk, nullptr), + ck_assert_msg(tox_add_tcp_relay(toxes[i], TOX_LOCALHOST, tcp_relay_port + (i % NUM_TCP_RELAYS), dpk, nullptr), "add relay error"); tox_self_get_dht_id(toxes[0], dpk); uint16_t first_port = tox_self_get_udp_port(toxes[0], nullptr); diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index 313fce96..a641e0a8 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -41b304348d45a0389807fa9bf45fec05b1c34e47905656923fb3cbc172c2c9ff /usr/local/bin/tox-bootstrapd +0bec5d4230562fff1e3b0d5902e95d168eab233ca0232d3fd62705c91c91f580 /usr/local/bin/tox-bootstrapd diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index b237b981..510a2518 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c @@ -830,8 +830,8 @@ static Socket new_listening_TCP_socket(const Logger *logger, Family family, uint if (!ok) { char *const error = net_new_strerror(net_error()); - LOGGER_ERROR(logger, "could not bind to TCP port %d (family = %d): %s", - port, family.value, error != nullptr ? error : "(null)"); + LOGGER_WARNING(logger, "could not bind to TCP port %d (family = %d): %s", + port, family.value, error != nullptr ? error : "(null)"); net_kill_strerror(error); kill_sock(sock); return net_invalid_socket;