From 264e7f9e6275fed2c33e55e6248e9fed7dec584e Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 10 Jul 2020 16:06:11 +0200 Subject: [PATCH] Merge #18638: net: Use mockable time for ping/pong, add tests fa3365430c5fb57d7c0b5f2bce9fbbe290be93c3 net: Use mockable time for ping/pong, add tests (MarcoFalke) faab4aaf2fa1153c6d76efc8113fa01b06943ece util: Add count_microseconds helper (MarcoFalke) Pull request description: Switch `CNode::m_ping_start` and `CNetMessage::m_time` to mockable time, so that tests can be added. Mockable time is also type-safe, since it uses `std::chrono` ACKs for top commit: jonatack: Code review re-ACK fa33654 re-read code, verified rebase per `git range-diff 4b5c919 fa94d6f fa33654`, previous tested ACKs still valid troygiorshev: ACK fa3365430c5fb57d7c0b5f2bce9fbbe290be93c3 Tree-SHA512: 7d632bd6019ce7c882029e71b667a61517e783af82755a85dd979ef09380934e172dec8b8f91d57b200a30a6e096aeaf01f19fee7f3aed0e0e871c72eb44d70e --- src/net.cpp | 3 +-- test/functional/p2p_ping.py | 8 ++------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 396ccad543..16be1f2629 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -785,8 +785,7 @@ void CNode::CopyStats(CNodeStats& stats) bool CNode::ReceiveMsgBytes(Span msg_bytes, bool& complete) { complete = false; - // TODO: use mocktime here after bitcoin#19499 is backported - const auto time = std::chrono::microseconds(GetTimeMicros()); + const auto time = GetTime(); LOCK(cs_vRecv); m_last_recv = std::chrono::duration_cast(time); nRecvBytes += msg_bytes.size(); diff --git a/test/functional/p2p_ping.py b/test/functional/p2p_ping.py index c4d3f56b62..8a55c3fa29 100755 --- a/test/functional/p2p_ping.py +++ b/test/functional/p2p_ping.py @@ -92,9 +92,7 @@ class PingPongTest(BitcoinTestFramework): self.mock_forward(ping_delay) no_pong_node.wait_until(lambda: 'ping' in no_pong_node.last_message) no_pong_node.send_and_ping(msg_pong(no_pong_node.last_message.pop('ping').nonce)) - # TODO this check doesn't work due to partial 18638 - # re-enable it after #19499 is done - # self.check_peer_info(pingtime=ping_delay, minping=ping_delay, pingwait=None) + self.check_peer_info(pingtime=ping_delay, minping=ping_delay, pingwait=None) self.log.info('Check that minping is decreased after a fast roundtrip') # mock time PING_INTERVAL ahead to trigger node into sending a ping @@ -104,9 +102,7 @@ class PingPongTest(BitcoinTestFramework): self.mock_forward(ping_delay) no_pong_node.wait_until(lambda: 'ping' in no_pong_node.last_message) no_pong_node.send_and_ping(msg_pong(no_pong_node.last_message.pop('ping').nonce)) - # TODO this check doesn't work due to partial 18638 - # re-enable it after #19499 is done - # self.check_peer_info(pingtime=ping_delay, minping=ping_delay, pingwait=None) + self.check_peer_info(pingtime=ping_delay, minping=ping_delay, pingwait=None) self.log.info('Check that peer is disconnected after ping timeout') assert 'ping' not in no_pong_node.last_message