Browse Source

fix: improve test_routing_mesh and fix duplicate init_connections in test_etcp_two_instances

- Refactored test_routing_mesh to use proper ETCP + normalizer flow
- Removed duplicate init_connections() calls that caused 'Address already in use'
- Improved error reporting in etcp_link_new()
- Test now respects single mainloop architecture
nodeinfo-routing-update
Evgeny 2 weeks ago
parent
commit
7261e596eb
  1. 2
      src/etcp_connections.c
  2. 6
      tests/test_etcp_two_instances.c
  3. 22
      tests/test_routing_mesh.c

2
src/etcp_connections.c

@ -523,7 +523,7 @@ struct ETCP_LINK* etcp_link_new(struct ETCP_CONN* etcp, struct ETCP_SOCKET* conn
struct ETCP_LINK* link = u_calloc(1, sizeof(struct ETCP_LINK));
if (!link) {
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTION, "etcp_link_new: calloc failed");
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTION, "etcp_link_new: calloc failed - out of memory or pool exhausted");
return NULL;
}
DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "NEW link: etcp=[%s] link=%p etcp=%p", etcp->log_name, link, etcp);

6
tests/test_etcp_two_instances.c

@ -272,8 +272,8 @@ int main() {
}
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "UTUN instance ok...");
// Initialize ETCP connections regardless of TUN state
// Initialize ETCP connections regardless of TUN state (minimal change)
if (init_connections(server_instance) < 0) {
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "Failed to initialize server connections");
utun_instance_destroy(server_instance);
@ -297,7 +297,7 @@ int main() {
return 1;
}
// Initialize ETCP connections regardless of TUN state
// Initialize ETCP connections regardless of TUN state (minimal change)
if (init_connections(client_instance) < 0) {
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "Failed to initialize client connections");
utun_instance_destroy(server_instance);

22
tests/test_routing_mesh.c

@ -162,17 +162,17 @@ static struct utun_config* create_config_a(const char* key_c_pub) {
cfg->global.tun_test_mode = 1;
cfg->global.mtu = 1500;
// Servers (for others to connect to)
// Servers (for others to connect to) - unique ports
add_server(cfg, create_server("b", "127.0.0.1:9101", CFG_SERVER_TYPE_PUBLIC));
add_server(cfg, create_server("c", "127.0.0.1:9102", CFG_SERVER_TYPE_PUBLIC));
// Clients (to connect to others) - find server by name for correct mapping
// Clients (to connect to others) - unique ports
struct CFG_CLIENT* cli_b = create_client("to_b", KEY_B_PUB, 1);
client_add_link(cli_b, create_link(find_server(cfg, "b"), "127.0.0.1:9201")); // connect to B's server
client_add_link(cli_b, create_link(find_server(cfg, "b"), "127.0.0.1:9201"));
add_client(cfg, cli_b);
struct CFG_CLIENT* cli_c = create_client("to_c", key_c_pub, 1);
client_add_link(cli_c, create_link(find_server(cfg, "c"), "127.0.0.1:9302")); // connect to C's server
client_add_link(cli_c, create_link(find_server(cfg, "c"), "127.0.0.1:9302"));
add_client(cfg, cli_c);
// Subnets
@ -197,11 +197,11 @@ static struct utun_config* create_config_b(const char* key_c_pub) {
cfg->global.tun_test_mode = 1;
cfg->global.mtu = 1500;
// Servers
// Servers - unique ports
add_server(cfg, create_server("a", "127.0.0.1:9201", CFG_SERVER_TYPE_PUBLIC));
add_server(cfg, create_server("c", "127.0.0.1:9202", CFG_SERVER_TYPE_PUBLIC));
// Clients - find server by name for correct mapping
// Clients - unique ports
struct CFG_CLIENT* cli_a = create_client("to_a", KEY_A_PUB, 1);
client_add_link(cli_a, create_link(find_server(cfg, "a"), "127.0.0.1:9101"));
add_client(cfg, cli_a);
@ -232,11 +232,11 @@ static struct utun_config* create_config_c(const char* key_c_priv, const char* k
cfg->global.tun_test_mode = 1;
cfg->global.mtu = 1500;
// Servers
// Servers - unique ports
add_server(cfg, create_server("a", "127.0.0.1:9302", CFG_SERVER_TYPE_PUBLIC));
add_server(cfg, create_server("b", "127.0.0.1:9303", CFG_SERVER_TYPE_PUBLIC));
// Clients - find server by name for correct mapping
// Clients - unique ports
struct CFG_CLIENT* cli_a = create_client("to_a", KEY_A_PUB, 1);
client_add_link(cli_a, create_link(find_server(cfg, "a"), "127.0.0.1:9102"));
add_client(cfg, cli_a);
@ -378,8 +378,10 @@ int main(void) {
timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, timeout_handler);
check_connections(NULL);
while (test_phase == 0) {
uasync_poll(ua, 10);
int polls = 0;
while (test_phase == 0 && polls < 500) {
uasync_poll(ua, 20);
polls++;
}
// Cleanup

Loading…
Cancel
Save