Skip to content

Commit

Permalink
Fix intermittent failure in TestReliableMessageProtocol. (#9927)
Browse files Browse the repository at this point in the history
We are ending up with queued retransmits on both the initiator and
responder.  The responder has a much longer retransmit interval, but
when we sleep for the initiator to retransmit, we can end up sleeping
too long, so the responder retransmits too.  Make the test handle both
cases.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Oct 2, 2021
1 parent 07dacd0 commit 6dce99d
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/messaging/tests/TestReliableMessageProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1226,18 +1226,34 @@ void CheckLostResponseWithPiggyback(nlTestSuite * inSuite, void * inContext)
// We resent our first message, which did not make it to the app-level
// listener on the receiver (because it's a duplicate) but did trigger a
// standalone ack.
NL_TEST_ASSERT(inSuite, gLoopback.mSentMessageCount == 4);
NL_TEST_ASSERT(inSuite, gLoopback.mDroppedMessageCount == 1);
NL_TEST_ASSERT(inSuite, !mockSender.IsOnMessageReceivedCalled);
NL_TEST_ASSERT(inSuite, !mockReceiver.IsOnMessageReceivedCalled);
NL_TEST_ASSERT(inSuite, rm->TestGetCountRetransTable() == 1);
//
// Now the annoying part is that depending on how long we _actually_ slept
// we might have also triggered the retransmit from the other side, even
// though we did not want to. Handle both cases here.
NL_TEST_ASSERT(inSuite, gLoopback.mSentMessageCount == 4 || gLoopback.mSentMessageCount == 6);
if (gLoopback.mSentMessageCount == 4)
{
// Just triggered the retransmit from the sender.
NL_TEST_ASSERT(inSuite, gLoopback.mDroppedMessageCount == 1);
NL_TEST_ASSERT(inSuite, !mockSender.IsOnMessageReceivedCalled);
NL_TEST_ASSERT(inSuite, !mockReceiver.IsOnMessageReceivedCalled);
NL_TEST_ASSERT(inSuite, rm->TestGetCountRetransTable() == 1);
}
else
{
// Also triggered the retransmit from the receiver.
NL_TEST_ASSERT(inSuite, gLoopback.mDroppedMessageCount == 1);
NL_TEST_ASSERT(inSuite, mockSender.IsOnMessageReceivedCalled);
NL_TEST_ASSERT(inSuite, !mockReceiver.IsOnMessageReceivedCalled);
NL_TEST_ASSERT(inSuite, rm->TestGetCountRetransTable() == 0);
}

// 1 tick is 64 ms, sleep 65*3 ms to trigger re-transmit from receiver
test_os_sleep_ms(65 * 3);
ReliableMessageMgr::Timeout(&ctx.GetSystemLayer(), rm);

// We resent our response message, which should show up as an app-level
// message and trigger a standalone ack.
// And now we've definitely resent our response message, which should show
// up as an app-level message and trigger a standalone ack.
NL_TEST_ASSERT(inSuite, gLoopback.mSentMessageCount == 6);
NL_TEST_ASSERT(inSuite, gLoopback.mDroppedMessageCount == 1);
NL_TEST_ASSERT(inSuite, mockSender.IsOnMessageReceivedCalled);
Expand Down

0 comments on commit 6dce99d

Please sign in to comment.