diff --git a/tests/client_server/client_server_test.cpp b/tests/client_server/client_server_test.cpp index e0980649..cb6fc68c 100644 --- a/tests/client_server/client_server_test.cpp +++ b/tests/client_server/client_server_test.cpp @@ -33,7 +33,7 @@ TEST(ClientServer, OneClient) { auto const loop_timeout = 1000_ms; auto s = createServer(); piMinSleep(); - auto c = createAndConnectClient>(); + auto c = createAndConnectClient>(); waitLoop([s]() { return s->clientsCount() > 0; }, loop_timeout); EXPECT_EQ(1, s->clientsCount()); @@ -103,7 +103,7 @@ int getClientsPings(const PIVector & clients) { TEST(ClientServer, ManyClients) { - auto const loop_timeout = 100_ms; + auto const loop_timeout = 1_s; constexpr int clients_count = 20; PIVector clients; auto s = createServer(); @@ -139,8 +139,9 @@ TEST(ClientServer, ManyClients) { for (const auto c: clients) { c->startSend(); } - loop_timeout.sleep(); + waitLoop([&clients]() { return getClientsPings(clients) > clients_count * 2; }, loop_timeout); EXPECT_TRUE(getClientsPings(clients) > clients_count * 2); + waitLoop([s]() { return getServerPongs(s) > clients_count * 2; }, loop_timeout); EXPECT_TRUE(getServerPongs(s) > clients_count * 2); piDeleteAllAndClear(clients); waitLoop([s]() { return s->clientsCount() == 0; }, loop_timeout); @@ -149,7 +150,7 @@ TEST(ClientServer, ManyClients) { } TEST(ClientServer, DynamicClients) { - auto const loop_timeout = 10_ms; + auto const loop_timeout = 3_s; constexpr int clients_count = 20; PIVector clients; PIMutex clients_mutex; @@ -199,15 +200,14 @@ TEST(ClientServer, DynamicClients) { }, 130_Hz); - (loop_timeout * clients_count).sleep(); - + waitLoop([s]() { return s->clientsCount() >= 10; }, loop_timeout); EXPECT_GE(s->clientsCount(), 10); deleteThread.stopAndWait(); spawnThread.stopAndWait(); piDeleteAllAndClear(clients); - waitLoop([s]() { return s->clientsCount() == 0; }, loop_timeout * clients_count); + waitLoop([s]() { return s->clientsCount() == 0; }, loop_timeout); EXPECT_EQ(0, s->clientsCount()); delete s;