diff options
author | chriseth <c@ethdev.com> | 2016-08-06 19:18:00 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2016-08-12 21:11:31 +0800 |
commit | b9f5b675a664ebdb1b28b87271783c59341ef3f1 (patch) | |
tree | 191b15f7ad1db1aa51d19a4f537fbddd55c21087 | |
parent | 53f68a155f071194fd779352d5997c03a6c387ed (diff) | |
download | dexon-solidity-b9f5b675a664ebdb1b28b87271783c59341ef3f1.tar.gz dexon-solidity-b9f5b675a664ebdb1b28b87271783c59341ef3f1.tar.zst dexon-solidity-b9f5b675a664ebdb1b28b87271783c59341ef3f1.zip |
Auto-calibrate mining sleep time.
-rw-r--r-- | test/RPCSession.cpp | 37 | ||||
-rw-r--r-- | test/RPCSession.h | 2 |
2 files changed, 30 insertions, 9 deletions
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<u256>(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<u256>(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<u256>(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) diff --git a/test/RPCSession.h b/test/RPCSession.h index 9b7009bf..2a9825b0 100644 --- a/test/RPCSession.h +++ b/test/RPCSession.h @@ -124,6 +124,8 @@ private: IPCSocket m_ipcSocket; size_t m_rpcSequence = 1; + unsigned m_sleepTime = 10; + unsigned m_successfulMineRuns = 0; std::vector<std::string> m_accounts; }; |