some fixes
PIEthernet::listen PIClientServer::Server::~Server PISystemTime const sleep ClientServer tests fast and stable
This commit is contained in:
@@ -72,11 +72,7 @@ PIClientServer::Server::~Server() {
|
||||
clean_thread->waitForFinish();
|
||||
piDeleteSafety(clean_thread);
|
||||
stopServer();
|
||||
for (auto c: clients) {
|
||||
c->aboutDelete();
|
||||
c->destroy();
|
||||
delete c;
|
||||
}
|
||||
closeAll();
|
||||
piDeleteSafety(tcp_server);
|
||||
}
|
||||
|
||||
|
||||
@@ -527,6 +527,7 @@ bool PIEthernet::listen(bool threaded) {
|
||||
listen_threaded = true;
|
||||
server_bounded = false;
|
||||
server_thread_.start(server_func);
|
||||
server_thread_.waitForStart();
|
||||
return true;
|
||||
}
|
||||
listen_threaded = server_bounded = false;
|
||||
|
||||
@@ -105,7 +105,7 @@ extern clock_serv_t __pi_mac_clock;
|
||||
//! Используйте этот метод для ожидания разниц системных времен или своего времени.
|
||||
//! Если метод будет вызван для системного времени \a PISystemTime::current(), то
|
||||
//! ожидание будет почти бесконечным
|
||||
void PISystemTime::sleep() {
|
||||
void PISystemTime::sleep() const {
|
||||
piUSleep(piFloord(toMicroseconds()));
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ void PISystemTime::toTimespec(void * ts) {
|
||||
}
|
||||
|
||||
|
||||
PISystemTime::Frequency PISystemTime::toFrequency() {
|
||||
PISystemTime::Frequency PISystemTime::toFrequency() const {
|
||||
return PISystemTime::Frequency::fromSystemTime(*this);
|
||||
}
|
||||
|
||||
|
||||
@@ -253,7 +253,7 @@ public:
|
||||
|
||||
//! \~english Sleep for this time
|
||||
//! \~russian Ожидать это время
|
||||
void sleep();
|
||||
void sleep() const;
|
||||
|
||||
//! \~english On *nix system assign current value to timespec struct
|
||||
//! \~russian На *nix системах присваивает время к timespec структуре
|
||||
@@ -261,7 +261,7 @@ public:
|
||||
|
||||
//! \~english Returns \a Frequency that corresponds this time interval
|
||||
//! \~russian Возвращает \a Frequency соответствующую этому временному интервалу
|
||||
PISystemTime::Frequency toFrequency();
|
||||
PISystemTime::Frequency toFrequency() const;
|
||||
|
||||
//! \~english Returns "yyyy-MM-dd hh:mm:ss.zzz" for absolute time and "<V> <d|h|m|s|ms|us|ns> ..." for relative
|
||||
//! \~russian Возвращает "yyyy-MM-dd hh:mm:ss.zzz" для абсолютного времени и "<V> <d|h|m|s|ms|us|ns> ..." для относительного
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user