From d10ee4ff08da5ac6b5614825ecdac6c3dc013c19 Mon Sep 17 00:00:00 2001 From: Steven van der Vegt Date: Fri, 18 Sep 2026 17:49:11 +0200 Subject: [PATCH] test(network): give the reconnect test a budget above the backoff TestNetworkIntegration_OutboundConnection11Reconnects waits defaultTimeout, 5 seconds, for node1 to reconnect to node2 after node2 was restarted. That reconnect races the backoff: connect() resets it to a random value between 1 and 5 seconds after a connection that was up is closed cleanly, and the connect loop only picks up expired backoffs once per second. The worst case is therefore already over the budget before dialling starts, and the test fails intermittently under load. The reconnect wait now has its own budget of 15 seconds. The two other waits in the test are an initial connect and a disconnect, neither of which races a backoff, so they keep defaultTimeout. Test-only. The tight budget dates back to #1874, which introduced the random reset. Assisted-by: AI (cherry picked from commit 71c1629d253eeaeaa007a2d073a7960b01bd15d4) --- network/network_integration_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/network/network_integration_test.go b/network/network_integration_test.go index f20885857..61e265851 100644 --- a/network/network_integration_test.go +++ b/network/network_integration_test.go @@ -59,6 +59,12 @@ import ( ) const defaultTimeout = 5 * time.Second + +// reconnectTimeout is the budget for a node to reconnect to a peer by itself, after a connection that was up was +// closed cleanly. connect() then resets the backoff to a random value between 1 and 5 seconds, and the connect +// loop only picks up expired backoffs once per second on top of that, so defaultTimeout does not cover the worst +// case and the test fails intermittently under load. +const reconnectTimeout = 15 * time.Second const payloadType = "test/transaction" var mutex = sync.Mutex{} @@ -828,7 +834,7 @@ func TestNetworkIntegration_OutboundConnection11Reconnects(t *testing.T) { node2 = startNode(t, "node2", testDirectory) // important to start a new instance, otherwise PeerID isn't regenerated if !test.WaitFor(t, func() (bool, error) { return len(node1.network.connectionManager.Peers()) == 1, nil - }, defaultTimeout, "time-out while waiting for node 1 to reconnect to node 2") { + }, reconnectTimeout, "time-out while waiting for node 1 to reconnect to node 2") { return }