diff --git a/src/test/app/LedgerReplay_test.cpp b/src/test/app/LedgerReplay_test.cpp index 2e2c80d6f8..0853affab7 100644 --- a/src/test/app/LedgerReplay_test.cpp +++ b/src/test/app/LedgerReplay_test.cpp @@ -28,7 +28,6 @@ #include #include -#include #include #include #include @@ -53,6 +52,7 @@ #include #include +#include #include #include #include @@ -402,7 +402,7 @@ public: enum class PeerSetBehavior { Good, - Drop50, + DropAlternate, DropAll, DropSkipListReply, DropLedgerDeltaReply, @@ -445,17 +445,13 @@ struct TestPeerSet : public PeerSet protocol::MessageType type, std::shared_ptr const& peer) override { - int dropRate = 0; - if (behavior == PeerSetBehavior::Drop50) - { - dropRate = 50; - } - else if (behavior == PeerSetBehavior::DropAll) - { - dropRate = 100; - } + if (behavior == PeerSetBehavior::DropAll) + return; - if (randInt(1, 100) <= dropRate) + // Drop every other message deterministically. Alternating drops + // still exercise the timeout/retry path while guaranteeing every + // subtask eventually gets a reply. + if (behavior == PeerSetBehavior::DropAlternate && sendCount++ % 2 == 0) return; switch (type) @@ -500,6 +496,7 @@ struct TestPeerSet : public PeerSet LedgerReplayMsgHandler& remote; std::shared_ptr dummyPeer; PeerSetBehavior behavior; + std::atomic sendCount{0}; }; /** @@ -1397,7 +1394,7 @@ struct LedgerReplayer_test : public beast::unit_test::Suite case PeerSetBehavior::Good: testcase("good network"); break; - case PeerSetBehavior::Drop50: + case PeerSetBehavior::DropAlternate: testcase("network drops 50% messages"); break; case PeerSetBehavior::Repeat: @@ -1613,7 +1610,7 @@ struct LedgerReplayer_test : public beast::unit_test::Suite testAllInboundLedgers(4); testPeerSetBehavior(PeerSetBehavior::Good, 1); testPeerSetBehavior(PeerSetBehavior::Good); - testPeerSetBehavior(PeerSetBehavior::Drop50); + testPeerSetBehavior(PeerSetBehavior::DropAlternate); testPeerSetBehavior(PeerSetBehavior::Repeat); testStop(); testSkipListBadReply();