Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exchange manager tests to handle losing timeslice better. #27872

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/messaging/tests/TestExchangeMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,19 @@ void CheckSessionExpirationDuringTimeout(nlTestSuite * inSuite, void * inContext
ExpireSessionFromTimeoutDelegate sendDelegate;
ExchangeContext * ec1 = ctx.NewExchangeToBob(&sendDelegate);

ec1->SetResponseTimeout(System::Clock::Timeout(100));
auto timeout = System::Clock::Timeout(100);
ec1->SetResponseTimeout(timeout);

NL_TEST_ASSERT(inSuite, !sendDelegate.IsOnResponseTimeoutCalled);

ec1->SendMessage(Protocols::BDX::Id, kMsgType_TEST1, System::PacketBufferHandle::New(System::PacketBuffer::kMaxSize),
SendFlags(Messaging::SendMessageFlags::kExpectResponse).Set(Messaging::SendMessageFlags::kNoAutoRequestAck));

ctx.DrainAndServiceIO();
NL_TEST_ASSERT(inSuite, !sendDelegate.IsOnResponseTimeoutCalled);

// Wait for our timeout to elapse. Give it an extra 100ms.
ctx.GetIOContext().DriveIOUntil(200_ms32, [&sendDelegate] { return sendDelegate.IsOnResponseTimeoutCalled; });
// Wait for our timeout to elapse. Give it an extra 1000ms of slack,
// because if we lose the timeslice for longer than the slack we could end
// up breaking out of the loop before the timeout timer has actually fired.
ctx.GetIOContext().DriveIOUntil(timeout + 1000_ms32, [&sendDelegate] { return sendDelegate.IsOnResponseTimeoutCalled; });

NL_TEST_ASSERT(inSuite, sendDelegate.IsOnResponseTimeoutCalled);

Expand Down