Skip to content

Commit 45b0bd5

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 4784eb0 commit 45b0bd5

1 file changed

Lines changed: 22 additions & 22 deletions

File tree

test/unit/tcp_server.cpp

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

2020
#include <atomic>
2121

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

2425
namespace boost::corosio {
25-
namespace {
2626

2727
class test_worker : public tcp_server::worker_base
2828
{
@@ -71,13 +71,13 @@ class test_server : public tcp_server
7171
}
7272
};
7373

74-
} // namespace
7574

75+
template<auto Backend>
7676
struct tcp_server_test
7777
{
7878
void testStopServer()
7979
{
80-
io_context ioc;
80+
io_context ioc(Backend);
8181
test_server srv(ioc);
8282

8383
// Bind to ephemeral port
@@ -113,7 +113,7 @@ struct tcp_server_test
113113

114114
void testStopWithActiveConnection()
115115
{
116-
io_context ioc;
116+
io_context ioc(Backend);
117117

118118
test_server srv(ioc);
119119
auto ec = srv.bind(endpoint(ipv4_address::loopback(), 0));
@@ -170,7 +170,7 @@ struct tcp_server_test
170170

171171
void testStartIdempotent()
172172
{
173-
io_context ioc;
173+
io_context ioc(Backend);
174174
test_server srv(ioc);
175175

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

194194
void testStopIdempotent()
195195
{
196-
io_context ioc;
196+
io_context ioc(Backend);
197197
test_server srv(ioc);
198198

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

218218
void testStopWithoutStart()
219219
{
220-
io_context ioc;
220+
io_context ioc(Backend);
221221
test_server srv(ioc);
222222

223223
auto ec = srv.bind(endpoint(ipv4_address::loopback(), 0));
@@ -232,7 +232,7 @@ struct tcp_server_test
232232
// Test the "stop the world" pattern:
233233
// start -> run -> stop -> run (drain) -> join -> restart
234234

235-
io_context ioc;
235+
io_context ioc(Backend);
236236

237237
test_server srv(ioc);
238238
auto ec = srv.bind(endpoint(ipv4_address::loopback(), 0));
@@ -326,7 +326,7 @@ struct tcp_server_test
326326
void testStartWithoutJoinThrows()
327327
{
328328
// Deterministic test: start() throws if previous session not joined
329-
io_context ioc;
329+
io_context ioc(Backend);
330330
test_server srv(ioc);
331331

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

366366
void testListenErrorCode()
367367
{
368-
io_context ioc;
368+
io_context ioc(Backend);
369369

370370
// Test success case
371371
tcp_acceptor acc1(ioc);
@@ -393,7 +393,7 @@ struct tcp_server_test
393393

394394
void testBindSuccess()
395395
{
396-
io_context ioc;
396+
io_context ioc(Backend);
397397

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

404404
void testBindErrorNonLocalAcceptor()
405405
{
406-
io_context ioc;
406+
io_context ioc(Backend);
407407

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

419419
void testBindErrorNonLocalAddress()
420420
{
421-
io_context ioc;
421+
io_context ioc(Backend);
422422

423423
// tcp_server::bind should return an error for non-local address
424424
test_server srv(ioc);
@@ -428,7 +428,7 @@ struct tcp_server_test
428428

429429
void testRelistenAfterClose()
430430
{
431-
io_context ioc;
431+
io_context ioc(Backend);
432432
tcp_acceptor acc(ioc);
433433

434434
// First listen
@@ -455,7 +455,7 @@ struct tcp_server_test
455455
{
456456
// Verify the noexcept move constructor leaves the source empty
457457
// and the destination with the original state.
458-
io_context ioc;
458+
io_context ioc(Backend);
459459
test_server src(ioc);
460460
auto ec = src.bind(endpoint(ipv4_address::loopback(), 0));
461461
BOOST_TEST(!ec);
@@ -472,7 +472,7 @@ struct tcp_server_test
472472
void testMoveAssign()
473473
{
474474
// Move-assign discards the existing impl_ and adopts the source.
475-
io_context ioc;
475+
io_context ioc(Backend);
476476
test_server a(ioc);
477477
test_server b(ioc);
478478

@@ -492,7 +492,7 @@ struct tcp_server_test
492492
// worker_base::run() never invokes the launcher; the launcher
493493
// destructor must return the worker to the idle pool via
494494
// push_sync. After stop() the accept loop completes cleanly.
495-
io_context ioc;
495+
io_context ioc(Backend);
496496

497497
class no_launch_worker : public tcp_server::worker_base
498498
{
@@ -568,7 +568,7 @@ struct tcp_server_test
568568
{
569569
// Multiple concurrent connections exercise the active list's
570570
// doubly-linked-list bookkeeping (push_back/remove with prev/next).
571-
io_context ioc;
571+
io_context ioc(Backend);
572572

573573
// Worker that holds the connection open until told to release.
574574
class slow_worker : public tcp_server::worker_base
@@ -672,7 +672,7 @@ struct tcp_server_test
672672
{
673673
// The second invocation of a launcher must throw logic_error.
674674
// We accept the connection but invoke launch twice inside run().
675-
io_context ioc;
675+
io_context ioc(Backend);
676676

677677
class throwing_worker : public tcp_server::worker_base
678678
{
@@ -761,7 +761,7 @@ struct tcp_server_test
761761
void testLocalEndpointOutOfRange()
762762
{
763763
// Index past the bound-ports list returns a default endpoint.
764-
io_context ioc;
764+
io_context ioc(Backend);
765765
test_server srv(ioc);
766766
auto ec = srv.bind(endpoint(ipv4_address::loopback(), 0));
767767
BOOST_TEST(!ec);
@@ -775,7 +775,7 @@ struct tcp_server_test
775775
// With one worker handling two sequential connections, the
776776
// second accept loop iteration must wait for the worker to
777777
// return (exercises pop_awaitable suspend / push_awaitable wake).
778-
io_context ioc;
778+
io_context ioc(Backend);
779779

780780
class one_worker_server : public tcp_server
781781
{
@@ -853,6 +853,6 @@ struct tcp_server_test
853853
}
854854
};
855855

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

858858
} // namespace boost::corosio

0 commit comments

Comments
 (0)