message: Add Tests for thinblocksinflight timeouts
diff: #include "primitives/block.h"
  #include "protocol.h"
  #include "random.h"
  +#include "requestManager.h"
  #include "serialize.h"
  #include "streams.h"
  #include "streams.h"
  @@ -1019,6 +1020,55 @@ BOOST_AUTO_TEST_CASE(thinblock_tests)
  vNodes.pop_back();
  dummyNode9.mapThinBlocksInFlight.erase(TestBlock1().GetHash());
  +
  + /*
  + * Test the disconnection of a peers with thinblocks in flight that has gone over the timeout limit
  + */
  + {
  + int64_t nStartTime = GetTime();
  + uint256 hash1 = uint256S("3fba505b48865fccda4e248cecc39d5dfbc6b8ef7b4adc9cd27242c1193c7141");
  + uint256 hash2 = uint256S("3fba505b48865fccda4e248cecc39d5dfbc6b8ef7b4adc9cd27242c1193c7142");
  +
  + CNode dummyNode1(INVALID_SOCKET, addr1, "", true);
  + dummyNode1.fDisconnect = false;
  + dummyNode1.fSuccessfullyConnected = true;
  +
  + CNode dummyNode2(INVALID_SOCKET, addr2, "", true);
  + dummyNode2.fDisconnect = false;
  + dummyNode2.fSuccessfullyConnected = true;
  +
  + SetMockTime(nStartTime);
  + AddThinBlockInFlight(&dummyNode1, hash1);
  + SetMockTime(nStartTime + 1);
  + AddThinBlockInFlight(&dummyNode1, hash2);
  + SetMockTime(nStartTime + 1);
  + AddThinBlockInFlight(&dummyNode2, hash1);
  +
  + // Move clock forward to the boundary of the timeout interval
  + // No nodes should be disconnected.
  + SetMockTime(nStartTime + (6 * blkReqRetryInterval / 1000000));
  + SendMessages(&dummyNode1);
  + SendMessages(&dummyNode2);
  + BOOST_CHECK(!dummyNode1.fDisconnect);
  + BOOST_CHECK(!dummyNode2.fDisconnect);
  +
  +
  + // Move clock forward to 1 second past the boundary of the timeout interval
  + // DummyNode1 should be disconnected
  + // DummyNode2 should still be connected because it was added one second later.
  + SetMockTime(nStartTime + (6 * blkReqRetryInterval / 1000000) + 1);
  + SendMessages(&dummyNode1);
  + SendMessages(&dummyNode2);
  + BOOST_CHECK(dummyNode1.fDisconnect);
  + BOOST_CHECK(!dummyNode2.fDisconnect);
  +
  + // Move clock forward to 1 second past the boundary of the timeout interval
  + // DummyNode2 should now be disconnected
  + SetMockTime(nStartTime + (6 * blkReqRetryInterval / 1000000) + 2);
  + SendMessages(&dummyNode2);
  + BOOST_CHECK(dummyNode2.fDisconnect);
  + }
  +
  excessiveBlockSize = old_excessiveBlockSize; // reset
  // cleanup received queues
  @@ -1027,9 +1077,7 @@ BOOST_AUTO_TEST_CASE(thinblock_tests)
  vRecv3.clear();
  vRecv4.clear();
  vRecv5.clear();
  - printf("test complete, cleaning up nodes\n");
  }
  - printf("node cleanup completed\n");
  }
  BOOST_AUTO_TEST_SUITE_END()
  