diff --git a/tests/test_etcp_two_instances b/tests/test_etcp_two_instances index d6af2586..3f243a52 100755 Binary files a/tests/test_etcp_two_instances and b/tests/test_etcp_two_instances differ diff --git a/tests/test_etcp_two_instances.c b/tests/test_etcp_two_instances.c index fdd0258f..d3be8ec2 100644 --- a/tests/test_etcp_two_instances.c +++ b/tests/test_etcp_two_instances.c @@ -13,7 +13,7 @@ #include "../src/secure_channel.h" #include "../lib/u_async.h" -#define TEST_TIMEOUT_MS 10000 // Increased from 5000 to 10000 ms +#define TEST_TIMEOUT_MS 3000 // Reduced to 3 seconds for faster testing static struct UTUN_INSTANCE* server_instance = NULL; static struct UTUN_INSTANCE* client_instance = NULL; @@ -35,6 +35,7 @@ static void monitor_connections(void* arg) { return; } + // Быстрый выход если уже есть подключение int server_links = 0; int client_links = 0; int client_initialized = 0; @@ -83,6 +84,12 @@ static void monitor_connections(void* arg) { if (client_initialized) { printf("\n=== SUCCESS: Client connection established! ===\n"); test_completed = 1; // Success + // Отменить таймаут теста для быстрого завершения + if (test_timeout_id) { + printf("[TEST] Cancelling test timeout for immediate exit\n"); + uasync_cancel_timeout(server_instance->ua, test_timeout_id); + test_timeout_id = NULL; + } return; } @@ -92,7 +99,7 @@ static void monitor_connections(void* arg) { // Schedule next check if (!test_completed) { - monitor_timeout_id = uasync_set_timeout(server_instance->ua, 1000, NULL, monitor_connections); // Check every 1s + monitor_timeout_id = uasync_set_timeout(server_instance->ua, 200, NULL, monitor_connections); // Check every 200ms for faster detection } } @@ -157,8 +164,8 @@ int main() { printf("Running event loop...\n\n"); // Give server time to fully initialize before client starts sending - printf("Waiting 2 seconds for server initialization...\n"); - for (int i = 0; i < 200; i++) { + printf("Waiting 0.5 seconds for server initialization...\n"); + for (int i = 0; i < 50; i++) { // Reduced from 200 to 50 iterations (0.5 seconds) if (server_ua) uasync_poll(server_ua, 10); if (client_ua) uasync_poll(client_ua, 10); usleep(10000); // 10ms @@ -166,12 +173,19 @@ int main() { printf("Starting connection attempts...\n"); int elapsed = 0; - while (!test_completed && elapsed < TEST_TIMEOUT_MS + 1000) { - if (server_ua) uasync_poll(server_ua, 10); - if (client_ua) uasync_poll(client_ua, 10); + int poll_interval = 5; // Reduced from 10ms to 5ms for faster response + while (!test_completed && elapsed < TEST_TIMEOUT_MS + 500) { + if (server_ua) uasync_poll(server_ua, poll_interval); + if (client_ua) uasync_poll(client_ua, poll_interval); - usleep(10000); // 10ms - elapsed += 10; + usleep(poll_interval * 1000); // microseconds + elapsed += poll_interval; + + // Быстрый выход если подключение установлено + if (test_completed == 1) { + printf("[TEST] Connection established, exiting early after %d ms\n", elapsed); + break; + } } // Cleanup