Skip to content

Commit b8d69a9

Browse files
Fix PerfdataWriterConnection test-cases on parallel build
1 parent 647b2b2 commit b8d69a9

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

test/perfdata-perfdatatargetfixture.hpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,24 @@ class PerfdataWriterTargetFixture
3939
explicit PerfdataWriterTargetFixture(AsioTlsOrTcpStream stream)
4040
: m_Stream(std::move(stream)),
4141
m_Acceptor(
42-
IoEngine::Get().GetIoContext(),
43-
boost::asio::ip::tcp::endpoint{boost::asio::ip::address_v4::loopback(), 0}
42+
IoEngine::Get().GetIoContext()
4443
)
4544
{
45+
boost::asio::ip::tcp::endpoint ep{boost::asio::ip::address_v4::loopback(), 0};
46+
m_Acceptor.open(ep.protocol());
47+
m_Acceptor.bind(ep);
4648
}
4749

4850
unsigned short GetPort() { return m_Acceptor.local_endpoint().port(); }
4951

52+
void Listen()
53+
{
54+
m_Acceptor.listen();
55+
}
56+
5057
void Accept()
5158
{
59+
Listen();
5260
BOOST_REQUIRE_NO_THROW(
5361
std::visit([&](auto& stream) { return m_Acceptor.accept(stream->lowest_layer()); }, m_Stream)
5462
);
@@ -63,11 +71,20 @@ class PerfdataWriterTargetFixture
6371
BOOST_REQUIRE(stream->next_layer().IsVerifyOK());
6472
}
6573

66-
void Shutdown()
74+
void Shutdown(bool wait = false)
6775
{
6876
BOOST_REQUIRE(std::holds_alternative<Shared<AsioTlsStream>::Ptr>(m_Stream));
6977
auto& stream = std::get<Shared<AsioTlsStream>::Ptr>(m_Stream);
7078
try {
79+
if (wait) {
80+
std::array<std::byte, 128> buf{};
81+
boost::asio::mutable_buffer readBuf (buf.data(), buf.size());
82+
boost::system::error_code ec;
83+
84+
do {
85+
stream->read_some(readBuf, ec);
86+
} while (!ec);
87+
}
7188
stream->next_layer().shutdown();
7289
} catch (const std::exception& ex) {
7390
if (const auto* se = dynamic_cast<const boost::system::system_error*>(&ex);

test/perfdata-perfdatawriterconnection.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,9 @@ BOOST_AUTO_TEST_CASE(finish_during_timeout)
130130
*/
131131
BOOST_AUTO_TEST_CASE(stuck_in_handshake)
132132
{
133-
TestThread mockTargetThread{[&]() { Accept(); }};
134-
135133
std::promise<void> p;
136134
TestThread timeoutThread{[&]() {
135+
Accept();
137136
auto f = p.get_future();
138137
GetConnection().CancelAfterTimeout(f, 50ms);
139138
BOOST_REQUIRE(f.wait_for(0ms) == std::future_status::timeout);
@@ -144,7 +143,6 @@ BOOST_AUTO_TEST_CASE(stuck_in_handshake)
144143
);
145144

146145
REQUIRE_JOINS_WITHIN(timeoutThread, 1s);
147-
REQUIRE_JOINS_WITHIN(mockTargetThread, 1s);
148146
}
149147

150148
/* When the disconnect timeout runs out while sending something to a slow or blocking server, we

0 commit comments

Comments
 (0)