From b9f5b675a664ebdb1b28b87271783c59341ef3f1 Mon Sep 17 00:00:00 2001 From: chriseth Date: Sat, 6 Aug 2016 13:18:00 +0200 Subject: Auto-calibrate mining sleep time. --- test/RPCSession.cpp | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'test/RPCSession.cpp') diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index 43ad26e1..de10b381 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -244,19 +244,38 @@ void RPCSession::test_mineBlocks(int _number) u256 startBlock = fromBigEndian(fromHex(rpcCall("eth_blockNumber").asString())); rpcCall("test_mineBlocks", { to_string(_number) }, true); - //@TODO do not use polling - but that would probably need a change to the test client - unsigned sleepTime = 10; - for (size_t polls = 0; polls < 10; ++polls) + 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 sleepTime = m_sleepTime; + size_t polls = 0; + for (; polls < 10 && !mined; ++polls) { - if (fromBigEndian(fromHex(rpcCall("eth_blockNumber").asString())) >= startBlock + _number) - return; std::this_thread::sleep_for(chrono::milliseconds(sleepTime)); - if (sleepTime > 500) - cout << "Mining timeout, sleeping for " << sleepTime << " ms" << endl; - sleepTime *= 2; + if (fromBigEndian(fromHex(rpcCall("eth_blockNumber").asString())) >= startBlock + _number) + mined = true; + else + sleepTime *= 2; + } + if (polls > 1) + { + m_successfulMineRuns = 0; + m_sleepTime += 2; + } + else if (polls == 1) + { + m_successfulMineRuns++; + if (m_successfulMineRuns > 5) + { + m_successfulMineRuns = 0; + m_sleepTime--; + } } - BOOST_FAIL("Error in test_mineBlocks: block mining timeout!"); + if (!mined) + BOOST_FAIL("Error in test_mineBlocks: block mining timeout!"); } void RPCSession::test_modifyTimestamp(size_t _timestamp) -- cgit