Skip to content

Commit f9fcd7d

Browse files
committed
test: run tcp_server tests on every backend
Parameterize the tcp_server suite on the backend tag via COROSIO_BACKEND_TESTS so its accept-loop, worker dispatch, and stop behavior run against each platform backend instead of only the default one.
1 parent 4c27533 commit f9fcd7d

1 file changed

Lines changed: 22 additions & 20 deletions

File tree

test/unit/tcp_server.cpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <atomic>
2121

22+
#include "context.hpp"
2223
#include "test_suite.hpp"
2324

2425
namespace boost::corosio {
@@ -73,11 +74,12 @@ class test_server : public tcp_server
7374

7475
} // namespace
7576

77+
template<auto Backend>
7678
struct tcp_server_test
7779
{
7880
void testStopServer()
7981
{
80-
io_context ioc;
82+
io_context ioc(Backend);
8183
test_server srv(ioc);
8284

8385
// Bind to ephemeral port
@@ -113,7 +115,7 @@ struct tcp_server_test
113115

114116
void testStopWithActiveConnection()
115117
{
116-
io_context ioc;
118+
io_context ioc(Backend);
117119

118120
test_server srv(ioc);
119121
auto ec = srv.bind(endpoint(ipv4_address::loopback(), 0));
@@ -170,7 +172,7 @@ struct tcp_server_test
170172

171173
void testStartIdempotent()
172174
{
173-
io_context ioc;
175+
io_context ioc(Backend);
174176
test_server srv(ioc);
175177

176178
auto ec = srv.bind(endpoint(ipv4_address::loopback(), 0));
@@ -193,7 +195,7 @@ struct tcp_server_test
193195

194196
void testStopIdempotent()
195197
{
196-
io_context ioc;
198+
io_context ioc(Backend);
197199
test_server srv(ioc);
198200

199201
auto ec = srv.bind(endpoint(ipv4_address::loopback(), 0));
@@ -217,7 +219,7 @@ struct tcp_server_test
217219

218220
void testStopWithoutStart()
219221
{
220-
io_context ioc;
222+
io_context ioc(Backend);
221223
test_server srv(ioc);
222224

223225
auto ec = srv.bind(endpoint(ipv4_address::loopback(), 0));
@@ -232,7 +234,7 @@ struct tcp_server_test
232234
// Test the "stop the world" pattern:
233235
// start -> run -> stop -> run (drain) -> join -> restart
234236

235-
io_context ioc;
237+
io_context ioc(Backend);
236238

237239
test_server srv(ioc);
238240
auto ec = srv.bind(endpoint(ipv4_address::loopback(), 0));
@@ -326,7 +328,7 @@ struct tcp_server_test
326328
void testStartWithoutJoinThrows()
327329
{
328330
// Deterministic test: start() throws if previous session not joined
329-
io_context ioc;
331+
io_context ioc(Backend);
330332
test_server srv(ioc);
331333

332334
auto ec = srv.bind(endpoint(ipv4_address::loopback(), 0));
@@ -365,7 +367,7 @@ struct tcp_server_test
365367

366368
void testListenErrorCode()
367369
{
368-
io_context ioc;
370+
io_context ioc(Backend);
369371

370372
// Test success case
371373
tcp_acceptor acc1(ioc);
@@ -393,7 +395,7 @@ struct tcp_server_test
393395

394396
void testBindSuccess()
395397
{
396-
io_context ioc;
398+
io_context ioc(Backend);
397399

398400
// Test that tcp_server::bind returns no error and doesn't throw
399401
test_server srv(ioc);
@@ -403,7 +405,7 @@ struct tcp_server_test
403405

404406
void testBindErrorNonLocalAcceptor()
405407
{
406-
io_context ioc;
408+
io_context ioc(Backend);
407409

408410
// Binding to a non-local IP address should fail with
409411
// "can't assign requested address" (EADDRNOTAVAIL) on all platforms.
@@ -418,7 +420,7 @@ struct tcp_server_test
418420

419421
void testBindErrorNonLocalAddress()
420422
{
421-
io_context ioc;
423+
io_context ioc(Backend);
422424

423425
// tcp_server::bind should return an error for non-local address
424426
test_server srv(ioc);
@@ -428,7 +430,7 @@ struct tcp_server_test
428430

429431
void testRelistenAfterClose()
430432
{
431-
io_context ioc;
433+
io_context ioc(Backend);
432434
tcp_acceptor acc(ioc);
433435

434436
// First listen
@@ -455,7 +457,7 @@ struct tcp_server_test
455457
{
456458
// Verify the noexcept move constructor leaves the source empty
457459
// and the destination with the original state.
458-
io_context ioc;
460+
io_context ioc(Backend);
459461
test_server src(ioc);
460462
auto ec = src.bind(endpoint(ipv4_address::loopback(), 0));
461463
BOOST_TEST(!ec);
@@ -472,7 +474,7 @@ struct tcp_server_test
472474
void testMoveAssign()
473475
{
474476
// Move-assign discards the existing impl_ and adopts the source.
475-
io_context ioc;
477+
io_context ioc(Backend);
476478
test_server a(ioc);
477479
test_server b(ioc);
478480

@@ -492,7 +494,7 @@ struct tcp_server_test
492494
// worker_base::run() never invokes the launcher; the launcher
493495
// destructor must return the worker to the idle pool via
494496
// push_sync. After stop() the accept loop completes cleanly.
495-
io_context ioc;
497+
io_context ioc(Backend);
496498

497499
class no_launch_worker : public tcp_server::worker_base
498500
{
@@ -568,7 +570,7 @@ struct tcp_server_test
568570
{
569571
// Multiple concurrent connections exercise the active list's
570572
// doubly-linked-list bookkeeping (push_back/remove with prev/next).
571-
io_context ioc;
573+
io_context ioc(Backend);
572574

573575
// Worker that holds the connection open until told to release.
574576
class slow_worker : public tcp_server::worker_base
@@ -672,7 +674,7 @@ struct tcp_server_test
672674
{
673675
// The second invocation of a launcher must throw logic_error.
674676
// We accept the connection but invoke launch twice inside run().
675-
io_context ioc;
677+
io_context ioc(Backend);
676678

677679
class throwing_worker : public tcp_server::worker_base
678680
{
@@ -761,7 +763,7 @@ struct tcp_server_test
761763
void testLocalEndpointOutOfRange()
762764
{
763765
// Index past the bound-ports list returns a default endpoint.
764-
io_context ioc;
766+
io_context ioc(Backend);
765767
test_server srv(ioc);
766768
auto ec = srv.bind(endpoint(ipv4_address::loopback(), 0));
767769
BOOST_TEST(!ec);
@@ -775,7 +777,7 @@ struct tcp_server_test
775777
// With one worker handling two sequential connections, the
776778
// second accept loop iteration must wait for the worker to
777779
// return (exercises pop_awaitable suspend / push_awaitable wake).
778-
io_context ioc;
780+
io_context ioc(Backend);
779781

780782
class one_worker_server : public tcp_server
781783
{
@@ -853,6 +855,6 @@ struct tcp_server_test
853855
}
854856
};
855857

856-
TEST_SUITE(tcp_server_test, "boost.corosio.tcp_server");
858+
COROSIO_BACKEND_TESTS(tcp_server_test, "boost.corosio.tcp_server")
857859

858860
} // namespace boost::corosio

0 commit comments

Comments
 (0)