some fixes

PIEthernet::listen
PIClientServer::Server::~Server
PISystemTime const sleep
ClientServer tests fast and stable
This commit is contained in:
2026-03-17 20:14:22 +03:00
parent 2798d7de9c
commit c02b627d47
5 changed files with 14 additions and 25 deletions

View File

@@ -32,6 +32,7 @@ Client * createAndConnectClient() {
TEST(ClientServer, OneClient) {
auto const loop_timeout = 1000_ms;
auto s = createServer<false, true>();
piMinSleep();
auto c = createAndConnectClient<TestClient<false, false>>();
waitLoop([s]() { return s->clientsCount() > 0; }, loop_timeout);
@@ -106,6 +107,7 @@ TEST(ClientServer, ManyClients) {
constexpr int clients_count = 20;
PIVector<ClientSendThread *> clients;
auto s = createServer<false, false, 100_KiB>();
piMinSleep();
piForTimes(clients_count) {
clients.append(new ClientSendThread());
@@ -137,7 +139,7 @@ TEST(ClientServer, ManyClients) {
for (const auto c: clients) {
c->startSend();
}
(100_ms).sleep();
loop_timeout.sleep();
EXPECT_TRUE(getClientsPings(clients) > clients_count * 2);
EXPECT_TRUE(getServerPongs(s) > clients_count * 2);
piDeleteAllAndClear(clients);
@@ -147,7 +149,7 @@ TEST(ClientServer, ManyClients) {
}
TEST(ClientServer, DynamicClients) {
auto const loop_timeout = 100_ms;
auto const loop_timeout = 10_ms;
constexpr int clients_count = 20;
PIVector<ClientSendThread *> clients;
PIMutex clients_mutex;
@@ -160,7 +162,6 @@ TEST(ClientServer, DynamicClients) {
clients_mutex.lock();
clients << c;
clients_mutex.unlock();
piCout << "new client" << clients.size();
};
piForTimes(clients_count) {
@@ -178,9 +179,8 @@ TEST(ClientServer, DynamicClients) {
piForTimes(new_cnt) {
spawnClient();
}
piCout << "+++++++";
},
12_Hz);
120_Hz);
deleteThread.start(
[&clients, &clients_mutex]() {
@@ -194,28 +194,20 @@ TEST(ClientServer, DynamicClients) {
clients_mutex.unlock();
if (c) {
delete c;
piCout << "remove client" << clients.size();
}
}
piCout << "----------";
},
13_Hz);
130_Hz);
(2_s).sleep();
(loop_timeout * clients_count).sleep();
EXPECT_GE(s->clientsCount(), 10);
piCout << "now clients" << clients.size();
deleteThread.stopAndWait();
spawnThread.stopAndWait();
piCout << "total clients" << clients.size();
piDeleteAllAndClear(clients);
waitLoop([s]() { return s->clientsCount() == 0; }, loop_timeout);
waitLoop([s]() { return s->clientsCount() == 0; }, loop_timeout * clients_count);
EXPECT_EQ(0, s->clientsCount());
delete s;