test: Improve stability of forwarding_test.

By trying to create a tox tcp relay on 100 ports starting at 36570.
This commit is contained in:
iphydf 2022-04-03 18:13:02 +00:00
parent 378febffff
commit 4d5887cc58
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9

View File

@ -34,7 +34,6 @@ static inline IP get_loopback(void)
#define NUM_FORWARDER_DHT (NUM_FORWARDER - NUM_FORWARDER_TCP) #define NUM_FORWARDER_DHT (NUM_FORWARDER - NUM_FORWARDER_TCP)
#define NUM_FORWARDING_ITERATIONS 1 #define NUM_FORWARDING_ITERATIONS 1
#define FORWARD_SEND_INTERVAL 2 #define FORWARD_SEND_INTERVAL 2
#define FORWARDER_TCP_RELAY_PORT 36570
#define FORWARDING_BASE_PORT 36571 #define FORWARDING_BASE_PORT 36571
typedef struct Test_Data { typedef struct Test_Data {
@ -180,12 +179,22 @@ static void test_forwarding(void)
printf("testing forwarding via tcp relays and dht\n"); printf("testing forwarding via tcp relays and dht\n");
struct Tox_Options *opts = tox_options_new(nullptr); struct Tox_Options *opts = tox_options_new(nullptr);
tox_options_set_tcp_port(opts, FORWARDER_TCP_RELAY_PORT); uint16_t forwarder_tcp_relay_port = 36570;
IP_Port relay_ipport_tcp = {ip, net_htons(FORWARDER_TCP_RELAY_PORT)}; Tox *relay = nullptr;
Tox *relay = tox_new_log(opts, nullptr, nullptr); // Try a few different ports.
for (uint8_t i = 0; i < 100; ++i) {
tox_options_set_tcp_port(opts, forwarder_tcp_relay_port);
relay = tox_new_log(opts, nullptr, nullptr);
if (relay != nullptr) {
break;
}
++forwarder_tcp_relay_port;
}
tox_options_free(opts); tox_options_free(opts);
ck_assert_msg(relay != nullptr, "Failed to create TCP relay"); ck_assert_msg(relay != nullptr, "Failed to create TCP relay");
IP_Port relay_ipport_tcp = {ip, net_htons(forwarder_tcp_relay_port)};
uint8_t dpk[TOX_PUBLIC_KEY_SIZE]; uint8_t dpk[TOX_PUBLIC_KEY_SIZE];
tox_self_get_dht_id(relay, dpk); tox_self_get_dht_id(relay, dpk);