Skip to content

Commit 0964874

Browse files
committed
fixed use of deprecated boost::asio::deadline_timer in tests
1 parent dbdde20 commit 0964874

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

test/transport/asio/timers.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ void run_dummy_server(int port) {
8080
// Wait for the specified time period then fail the test
8181
void run_test_timer(long value) {
8282
boost::asio::io_context ctx;
83-
boost::asio::deadline_timer t(ctx,boost::posix_time::milliseconds(value));
83+
boost::asio::system_timer t(ctx);
84+
t.expires_after(std::chrono::milliseconds(value));
8485
boost::system::error_code ec;
8586
t.wait(ec);
8687
BOOST_FAIL( "Test timed out" );

test/transport/integration.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -355,17 +355,18 @@ void close(T * e, websocketpp::connection_hdl hdl) {
355355
e->get_con_from_hdl(hdl)->close(websocketpp::close::status::normal,"");
356356
}
357357

358-
class test_deadline_timer
358+
class test_system_timer
359359
{
360360
public:
361-
test_deadline_timer(int seconds)
362-
: m_timer(m_io_context, boost::posix_time::seconds(seconds))
361+
test_system_timer(int seconds)
362+
: m_timer(m_io_context)
363363
{
364-
m_timer.async_wait(bind(&test_deadline_timer::expired, this, ::_1));
364+
m_timer.expires_after(std::chrono::seconds(seconds));
365+
m_timer.async_wait(bind(&test_system_timer::expired, this, ::_1));
365366
std::size_t (websocketpp::lib::asio::io_context::*run)() = &websocketpp::lib::asio::io_context::run;
366367
m_timer_thread = websocketpp::lib::thread(websocketpp::lib::bind(run, &m_io_context));
367368
}
368-
~test_deadline_timer()
369+
~test_system_timer()
369370
{
370371
m_timer.cancel();
371372
m_timer_thread.join();
@@ -381,7 +382,7 @@ class test_deadline_timer
381382
}
382383

383384
websocketpp::lib::asio::io_context m_io_context;
384-
websocketpp::lib::asio::deadline_timer m_timer;
385+
websocketpp::lib::asio::system_timer m_timer;
385386
websocketpp::lib::thread m_timer_thread;
386387
};
387388

@@ -427,7 +428,7 @@ BOOST_AUTO_TEST_CASE( pong_timeout ) {
427428
websocketpp::lib::thread sthread(websocketpp::lib::bind(&run_server,&s,9005,false));
428429
sleep(1); // give the server thread some time to start
429430

430-
test_deadline_timer deadline(10);
431+
test_system_timer deadline(10);
431432

432433
run_client(c, "http://localhost:9005",false);
433434

@@ -448,7 +449,7 @@ BOOST_AUTO_TEST_CASE( client_open_handshake_timeout ) {
448449

449450
sleep(1); // give the server thread some time to start
450451

451-
test_deadline_timer deadline(10);
452+
test_system_timer deadline(10);
452453

453454
run_client(c, "http://localhost:9005");
454455
}
@@ -464,7 +465,7 @@ BOOST_AUTO_TEST_CASE( server_open_handshake_timeout ) {
464465

465466
websocketpp::lib::thread sthread(websocketpp::lib::bind(&run_server,&s,9005,false));
466467

467-
test_deadline_timer deadline(10);
468+
test_system_timer deadline(10);
468469

469470
sleep(1); // give the server thread some time to start
470471

@@ -489,7 +490,7 @@ BOOST_AUTO_TEST_CASE( client_self_initiated_close_handshake_timeout ) {
489490

490491
websocketpp::lib::thread sthread(websocketpp::lib::bind(&run_server,&s,9005,false));
491492

492-
test_deadline_timer deadline(10);
493+
test_system_timer deadline(10);
493494

494495
sleep(1); // give the server thread some time to start
495496

@@ -522,7 +523,7 @@ BOOST_AUTO_TEST_CASE( server_self_initiated_close_handshake_timeout ) {
522523
c.set_open_handler(bind(&delay,::_1,1));
523524

524525
websocketpp::lib::thread sthread(websocketpp::lib::bind(&run_server,&s,9005,false));
525-
test_deadline_timer deadline(10);
526+
test_system_timer deadline(10);
526527

527528
sleep(1); // give the server thread some time to start
528529

@@ -534,7 +535,7 @@ BOOST_AUTO_TEST_CASE( server_self_initiated_close_handshake_timeout ) {
534535
BOOST_AUTO_TEST_CASE( client_runs_out_of_work ) {
535536
client c;
536537

537-
test_deadline_timer deadline(3);
538+
test_system_timer deadline(3);
538539

539540
websocketpp::lib::error_code ec;
540541
c.init_asio(ec);
@@ -600,7 +601,7 @@ BOOST_AUTO_TEST_CASE( stop_listening ) {
600601
c.set_open_handler(bind(&close<client>,&c,::_1));
601602

602603
websocketpp::lib::thread sthread(websocketpp::lib::bind(&run_server,&s,9005,false));
603-
test_deadline_timer deadline(5);
604+
test_system_timer deadline(5);
604605

605606
sleep(1); // give the server thread some time to start
606607

0 commit comments

Comments
 (0)