Skip to content

Commit

Permalink
Assert only side effects in ping test
Browse files Browse the repository at this point in the history
  • Loading branch information
ashtum committed Feb 15, 2024
1 parent a6fd05c commit 46f71d8
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions test/beast/websocket/ping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,9 @@ class ping_test : public websocket_test_suite
{
echo_server es{log};
stream<test::stream> ws{ioc_};

// We have an inactivity timeout of 2s, but don't send pings
ws.set_option(stream_base::timeout{
stream_base::none(),
std::chrono::milliseconds(2000),
std::chrono::milliseconds(500),
false
});
ws.next_layer().connect(es.stream());
Expand All @@ -112,28 +110,11 @@ class ping_test : public websocket_test_suite
system_error{ec});
got_timeout = true;
});
// We are connected, base state
BEAST_EXPECT(ws.impl_->idle_counter == 0);

test::run_for(ioc_, std::chrono::milliseconds(1250));
// After 1.25s idle, no timeout but idle counter is 1
BEAST_EXPECT(ws.impl_->idle_counter == 1);

test::run_for(ioc_, std::chrono::milliseconds(300));
es.async_ping();
test::run_for(ioc_, std::chrono::milliseconds(500));
// The server sent a ping at 1.25s mark, and we're now at 1.75s mark.
// We haven't hit the idle timer yet (happens at 1s, 2s, 3s)
BEAST_EXPECT(ws.impl_->idle_counter == 0);
test::run_for(ioc_, std::chrono::milliseconds(300));
BEAST_EXPECT(!got_timeout);

test::run_for(ioc_, std::chrono::milliseconds(750));
// At 2.5s total; should have triggered the idle timer
BEAST_EXPECT(ws.impl_->idle_counter == 1);
BEAST_EXPECT(!got_timeout);

test::run_for(ioc_, std::chrono::milliseconds(750));
// At 3s total; should have triggered the idle timer again without
// activity and triggered timeout.
test::run_for(ioc_, std::chrono::milliseconds(300));
BEAST_EXPECT(got_timeout);
}

Expand Down

0 comments on commit 46f71d8

Please sign in to comment.