diff options
author | subtly <subtly@users.noreply.github.com> | 2015-04-14 15:24:56 +0800 |
---|---|---|
committer | subtly <subtly@users.noreply.github.com> | 2015-04-14 15:24:56 +0800 |
commit | 4f68bb8d450f469375473647705c6cf5d32d4f54 (patch) | |
tree | d8373ba22dd155f9862c3b076a88bfd95ebe0f1c /net.cpp | |
parent | 2560af3a1da5162063c19817fdbd8e64bf6d4e42 (diff) | |
parent | 4615f8cd1a7a61283de149a7f6f75f4910ee4b3b (diff) | |
download | dexon-solidity-4f68bb8d450f469375473647705c6cf5d32d4f54.tar dexon-solidity-4f68bb8d450f469375473647705c6cf5d32d4f54.tar.gz dexon-solidity-4f68bb8d450f469375473647705c6cf5d32d4f54.tar.bz2 dexon-solidity-4f68bb8d450f469375473647705c6cf5d32d4f54.tar.lz dexon-solidity-4f68bb8d450f469375473647705c6cf5d32d4f54.tar.xz dexon-solidity-4f68bb8d450f469375473647705c6cf5d32d4f54.tar.zst dexon-solidity-4f68bb8d450f469375473647705c6cf5d32d4f54.zip |
Merge branch 'p2p' into discoveryEndpoints
Diffstat (limited to 'net.cpp')
-rw-r--r-- | net.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -151,6 +151,39 @@ public: bool success = false; }; +BOOST_AUTO_TEST_CASE(requestTimeout) +{ + using TimePoint = std::chrono::steady_clock::time_point; + using RequestTimeout = std::pair<NodeId, TimePoint>; + + std::chrono::milliseconds timeout(300); + std::list<RequestTimeout> timeouts; + + NodeId nodeA(sha3("a")); + NodeId nodeB(sha3("b")); + timeouts.push_back(make_pair(nodeA, chrono::steady_clock::now())); + this_thread::sleep_for(std::chrono::milliseconds(100)); + timeouts.push_back(make_pair(nodeB, chrono::steady_clock::now())); + this_thread::sleep_for(std::chrono::milliseconds(210)); + + bool nodeAtriggered = false; + bool nodeBtriggered = false; + timeouts.remove_if([&](RequestTimeout const& t) + { + auto now = chrono::steady_clock::now(); + auto diff = now - t.second; + if (t.first == nodeA && diff < timeout) + nodeAtriggered = true; + if (t.first == nodeB && diff < timeout) + nodeBtriggered = true; + return (t.first == nodeA || t.first == nodeB); + }); + + BOOST_REQUIRE(nodeAtriggered == false); + BOOST_REQUIRE(nodeBtriggered == true); + BOOST_REQUIRE(timeouts.size() == 0); +} + BOOST_AUTO_TEST_CASE(isIPAddressType) { string wildcard = "0.0.0.0"; |