fix(ci): PollSetTest::testPollClosedServer() intermittently fails #4205

This commit is contained in:
Aleksandar Fabijanic
2023-10-21 17:39:36 +02:00
parent 3793c0a515
commit 39e2da88d5
2 changed files with 30 additions and 14 deletions

View File

@@ -132,7 +132,7 @@ jobs:
CppUnit::TestCaller<ExpireLRUCacheTest>.testAccessExpireN,
CppUnit::TestCaller<UniqueExpireLRUCacheTest>.testExpireN,
CppUnit::TestCaller<ExpireLRUCacheTest>.testAccessExpireN,
CppUnit::TestCaller<PollSetTest>.testPollClosedServer"
CppUnit::TestCaller<SyslogTest>.testOldBSD"
EXCLUDE_TESTS="Redis Data/MySQL Data/ODBC Data/PostgreSQL MongoDB PDF"
./ci/runtests.sh

View File

@@ -338,15 +338,19 @@ void PollSetTest::testPollNoServer()
assertTrue(ps.has(ss1));
assertTrue(ps.has(ss2));
PollSet::SocketModeMap sm;
int signalled = 0;
Stopwatch sw; sw.start();
do
{
sm = ps.poll(Timespan(1000000));
for (auto s : sm)
assertTrue(0 != (s.second & PollSet::POLL_ERROR));
signalled += static_cast<int>(sm.size());
if (sw.elapsedSeconds() > 10) fail();
} while (sm.size() < 2);
assertTrue(sm.size() == 2);
for (auto s : sm)
assertTrue(0 != (s.second & PollSet::POLL_ERROR));
} while (signalled < 2);
assertTrue(signalled == 2);
}
@@ -359,6 +363,7 @@ void PollSetTest::testPollClosedServer()
ss1.connect(SocketAddress("127.0.0.1", echoServer1.port()));
ss2.connect(SocketAddress("127.0.0.1", echoServer2.port()));
PollSet ps;
assertTrue(ps.empty());
ps.add(ss1, PollSet::POLL_READ);
@@ -367,22 +372,33 @@ void PollSetTest::testPollClosedServer()
assertTrue(ps.has(ss1));
assertTrue(ps.has(ss2));
std::string str = "HELLO";
int len = static_cast<int>(str.length());
echoServer1.stop();
ss1.sendBytes("HELLO", 5);
// echoServer is blocked waiting for data, send some
assertTrue (len == ss1.sendBytes(str.data(), len));
// the stop flag should kick in, wait for it ...
while (!echoServer1.done()) Thread::sleep(10);
echoServer2.stop();
ss2.sendBytes("HELLO", 5);
assertTrue (len == ss2.sendBytes(str.data(), len));
while (!echoServer2.done()) Thread::sleep(10);
PollSet::SocketModeMap sm;
int signalled = 0;
Stopwatch sw; sw.start();
do
{
sm = ps.poll(Timespan(1000000));
if (sw.elapsedSeconds() > 10) fail();
} while (sm.size() < 2);
assertTrue(sm.size() == 2);
assertTrue(0 == ss1.receiveBytes(0, 0));
assertTrue(0 == ss2.receiveBytes(0, 0));
signalled += static_cast<int>(ps.poll(Timespan(1000000)).size());
int secs = sw.elapsedSeconds();
if (secs > 10)
fail(Poco::format("timed out after %ds, sockets signalled=%z (expected 2)", secs, signalled), __LINE__);
} while (signalled < 2);
assertTrue(signalled == 2);
// socket closed or error
assertTrue(0 >= ss1.receiveBytes(0, 0));
assertTrue(0 >= ss2.receiveBytes(0, 0));
}