mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
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
This commit is contained in:
parent
6e5d3f1d1f
commit
264e7f9e62
@ -785,8 +785,7 @@ void CNode::CopyStats(CNodeStats& stats)
|
|||||||
bool CNode::ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete)
|
bool CNode::ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete)
|
||||||
{
|
{
|
||||||
complete = false;
|
complete = false;
|
||||||
// TODO: use mocktime here after bitcoin#19499 is backported
|
const auto time = GetTime<std::chrono::microseconds>();
|
||||||
const auto time = std::chrono::microseconds(GetTimeMicros());
|
|
||||||
LOCK(cs_vRecv);
|
LOCK(cs_vRecv);
|
||||||
m_last_recv = std::chrono::duration_cast<std::chrono::seconds>(time);
|
m_last_recv = std::chrono::duration_cast<std::chrono::seconds>(time);
|
||||||
nRecvBytes += msg_bytes.size();
|
nRecvBytes += msg_bytes.size();
|
||||||
|
@ -92,9 +92,7 @@ class PingPongTest(BitcoinTestFramework):
|
|||||||
self.mock_forward(ping_delay)
|
self.mock_forward(ping_delay)
|
||||||
no_pong_node.wait_until(lambda: 'ping' in no_pong_node.last_message)
|
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))
|
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
|
self.check_peer_info(pingtime=ping_delay, minping=ping_delay, pingwait=None)
|
||||||
# re-enable it after #19499 is done
|
|
||||||
# self.check_peer_info(pingtime=ping_delay, minping=ping_delay, pingwait=None)
|
|
||||||
|
|
||||||
self.log.info('Check that minping is decreased after a fast roundtrip')
|
self.log.info('Check that minping is decreased after a fast roundtrip')
|
||||||
# mock time PING_INTERVAL ahead to trigger node into sending a ping
|
# mock time PING_INTERVAL ahead to trigger node into sending a ping
|
||||||
@ -104,9 +102,7 @@ class PingPongTest(BitcoinTestFramework):
|
|||||||
self.mock_forward(ping_delay)
|
self.mock_forward(ping_delay)
|
||||||
no_pong_node.wait_until(lambda: 'ping' in no_pong_node.last_message)
|
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))
|
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
|
self.check_peer_info(pingtime=ping_delay, minping=ping_delay, pingwait=None)
|
||||||
# re-enable it after #19499 is done
|
|
||||||
# self.check_peer_info(pingtime=ping_delay, minping=ping_delay, pingwait=None)
|
|
||||||
|
|
||||||
self.log.info('Check that peer is disconnected after ping timeout')
|
self.log.info('Check that peer is disconnected after ping timeout')
|
||||||
assert 'ping' not in no_pong_node.last_message
|
assert 'ping' not in no_pong_node.last_message
|
||||||
|
Loading…
Reference in New Issue
Block a user