Skip to content

Commit

Permalink
Fix flakyness in Test_network on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Flamefire committed Nov 16, 2023
1 parent dac0b7e commit 08d6c0e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 3 additions & 2 deletions tests/s25Main/network/TestServer.cpp
Expand Up @@ -41,15 +41,16 @@ bool TestServer::run(bool waitForConnection)
{
if(set.InSet(connections[id].so))
{
// nachricht empfangen
if(connections[id].recvQueue.recv(connections[id].so) < 0)
connections.erase(connections.begin() + id);
else
{
msgReceived = true;
++id;
}
} else
} else if(!connections[id].so.isValid())
connections.erase(connections.begin() + id); // LCOV_EXCL_LINE
else
++id;
}
} while(msgReceived);
Expand Down
13 changes: 10 additions & 3 deletions tests/s25Main/network/main.cpp
Expand Up @@ -5,6 +5,7 @@
#define BOOST_TEST_MODULE RTTR_Network

#include "TestServer.h"
#include "helpers/CIUtils.h"
#include <rttr/test/Fixture.hpp>
#include <s25util/Socket.h>
#include <boost/test/unit_test.hpp>
Expand All @@ -28,9 +29,7 @@ BOOST_AUTO_TEST_CASE(TestServer_Works)
auto runServer = [&server]() {
const auto result = server.run();
for(int i = 0; i < 5; i++)
{
BOOST_TEST(server.run() == result);
}
return result;
};
BOOST_TEST(!runServer());
Expand All @@ -54,5 +53,13 @@ BOOST_AUTO_TEST_CASE(TestServer_Works)
BOOST_TEST(runServer());
sock.Close();
BOOST_TEST(runServer());
BOOST_TEST_REQUIRE(server.connections.size() == 1u);
if(rttr::isRunningOnCI()) // On CI retry to avoid flakes
{
for(int i = 0; i < 5; i++)
{
if(server.connections.size() == 2u)
BOOST_TEST(runServer()); // LCOV_EXCL_LINE
}
}
BOOST_TEST(server.connections.size() == 1u);
}

0 comments on commit 08d6c0e

Please sign in to comment.