aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsubtly <subtly@users.noreply.github.com>2015-04-12 04:03:56 +0800
committersubtly <subtly@users.noreply.github.com>2015-04-12 04:03:56 +0800
commite51bdd01229b3494a13ff4d5804fca2f916ba111 (patch)
tree827b43a4db734c7f814a3eee20b8112cc816c64f
parentc111dbff3f4d4d5e6d064b38bcd645f2d763ccab (diff)
downloaddexon-solidity-e51bdd01229b3494a13ff4d5804fca2f916ba111.tar
dexon-solidity-e51bdd01229b3494a13ff4d5804fca2f916ba111.tar.gz
dexon-solidity-e51bdd01229b3494a13ff4d5804fca2f916ba111.tar.bz2
dexon-solidity-e51bdd01229b3494a13ff4d5804fca2f916ba111.tar.lz
dexon-solidity-e51bdd01229b3494a13ff4d5804fca2f916ba111.tar.xz
dexon-solidity-e51bdd01229b3494a13ff4d5804fca2f916ba111.tar.zst
dexon-solidity-e51bdd01229b3494a13ff4d5804fca2f916ba111.zip
test use of steady_clock for timeout
-rw-r--r--net.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/net.cpp b/net.cpp
index ec1efb36..75c67888 100644
--- a/net.cpp
+++ b/net.cpp
@@ -145,6 +145,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";