From 1d4ef87bb11e447334d2dea99b5a70c7201d6b97 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 13 Feb 2017 13:59:29 +0000 Subject: [PATCH 1/3] Use maxMiningTime in mining as opposed to poll counter --- test/RPCSession.cpp | 12 ++++++++---- test/RPCSession.h | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index c27e73d42..613d042af 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -248,22 +248,26 @@ void RPCSession::test_mineBlocks(int _number) // We auto-calibrate the time it takes to mine the transaction. // It would be better to go without polling, but that would probably need a change to the test client + unsigned startTime = boost::posix_time::microsec_clock::local_time(); unsigned sleepTime = m_sleepTime; - size_t polls = 0; - for (; polls < 14 && !mined; ++polls) + size_t tries = 0; + for (; !mined; ++tries) { std::this_thread::sleep_for(chrono::milliseconds(sleepTime)); + boost::posix_time::time_duration timeSpent = boost::posix_time::microsec_clock::local_time() - startTime; + if (timeSpent > m_maxMiningTime) + break; if (fromBigEndian(fromHex(rpcCall("eth_blockNumber").asString())) >= startBlock + _number) mined = true; else sleepTime *= 2; } - if (polls > 1) + if (tries > 1) { m_successfulMineRuns = 0; m_sleepTime += 2; } - else if (polls == 1) + else if (tries == 1) { m_successfulMineRuns++; if (m_successfulMineRuns > 5) diff --git a/test/RPCSession.h b/test/RPCSession.h index 105ba3788..a0b1e9ef4 100644 --- a/test/RPCSession.h +++ b/test/RPCSession.h @@ -126,6 +126,7 @@ private: IPCSocket m_ipcSocket; size_t m_rpcSequence = 1; + unsigned m_maxMiningTime = 15000; // 15 seconds unsigned m_sleepTime = 10; unsigned m_successfulMineRuns = 0; From e9dd9d2c7220594e2731b081990396429c5288d7 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 13 Feb 2017 14:10:02 +0000 Subject: [PATCH 2/3] Simplify mining loop --- test/RPCSession.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index 613d042af..bf639e195 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -243,22 +243,20 @@ void RPCSession::test_mineBlocks(int _number) u256 startBlock = fromBigEndian(fromHex(rpcCall("eth_blockNumber").asString())); BOOST_REQUIRE(rpcCall("test_mineBlocks", { to_string(_number) }, true) == true); - bool mined = false; - // We auto-calibrate the time it takes to mine the transaction. // It would be better to go without polling, but that would probably need a change to the test client unsigned startTime = boost::posix_time::microsec_clock::local_time(); unsigned sleepTime = m_sleepTime; size_t tries = 0; - for (; !mined; ++tries) + for (; ; ++tries) { std::this_thread::sleep_for(chrono::milliseconds(sleepTime)); boost::posix_time::time_duration timeSpent = boost::posix_time::microsec_clock::local_time() - startTime; if (timeSpent > m_maxMiningTime) - break; + BOOST_FAIL("Error in test_mineBlocks: block mining timeout!"); if (fromBigEndian(fromHex(rpcCall("eth_blockNumber").asString())) >= startBlock + _number) - mined = true; + break; else sleepTime *= 2; } @@ -277,9 +275,6 @@ void RPCSession::test_mineBlocks(int _number) m_sleepTime--; } } - - if (!mined) - BOOST_FAIL("Error in test_mineBlocks: block mining timeout!"); } void RPCSession::test_modifyTimestamp(size_t _timestamp) From 0fe788aad6d55c440e04f6f64f1927613bd6b16b Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 13 Feb 2017 15:01:15 +0000 Subject: [PATCH 3/3] Use std::chrono and not boost::posix_Time --- test/RPCSession.cpp | 5 +++-- test/RPCSession.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index bf639e195..ff00d7833 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -246,13 +246,14 @@ void RPCSession::test_mineBlocks(int _number) // We auto-calibrate the time it takes to mine the transaction. // It would be better to go without polling, but that would probably need a change to the test client - unsigned startTime = boost::posix_time::microsec_clock::local_time(); + auto startTime = std::chrono::steady_clock::now(); unsigned sleepTime = m_sleepTime; size_t tries = 0; for (; ; ++tries) { std::this_thread::sleep_for(chrono::milliseconds(sleepTime)); - boost::posix_time::time_duration timeSpent = boost::posix_time::microsec_clock::local_time() - startTime; + auto endTime = std::chrono::steady_clock::now(); + unsigned timeSpent = std::chrono::duration_cast(endTime - startTime).count(); if (timeSpent > m_maxMiningTime) BOOST_FAIL("Error in test_mineBlocks: block mining timeout!"); if (fromBigEndian(fromHex(rpcCall("eth_blockNumber").asString())) >= startBlock + _number) diff --git a/test/RPCSession.h b/test/RPCSession.h index a0b1e9ef4..414db3232 100644 --- a/test/RPCSession.h +++ b/test/RPCSession.h @@ -127,7 +127,7 @@ private: IPCSocket m_ipcSocket; size_t m_rpcSequence = 1; unsigned m_maxMiningTime = 15000; // 15 seconds - unsigned m_sleepTime = 10; + unsigned m_sleepTime = 10; // 10 milliseconds unsigned m_successfulMineRuns = 0; std::vector m_accounts;