diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index 5a0fb5acd..ebc935c38 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -3151,16 +3151,6 @@ const ( // are sent. heartbeatInterval = 2 * time.Second - // discoPingInterval is the minimum time between pings - // to an endpoint. (Except in the case of CallMeMaybe frames - // resetting the counter, as the first pings likely didn't through - // the firewall) - discoPingInterval = 5 * time.Second - - // pingTimeoutDuration is how long we wait for a pong reply before - // assuming it's never coming. - pingTimeoutDuration = 5 * time.Second - // trustUDPAddrDuration is how long we trust a UDP address as the exclusive // path (without using DERP) without having heard a Pong reply. trustUDPAddrDuration = 5 * time.Second @@ -3183,6 +3173,19 @@ const ( endpointsFreshEnoughDuration = 27 * time.Second ) +// Constants that are variable for testing. +var ( + // pingTimeoutDuration is how long we wait for a pong reply before + // assuming it's never coming. + pingTimeoutDuration = 5 * time.Second + + // discoPingInterval is the minimum time between pings + // to an endpoint. (Except in the case of CallMeMaybe frames + // resetting the counter, as the first pings likely didn't through + // the firewall) + discoPingInterval = 5 * time.Second +) + // endpointState is some state and history for a specific endpoint of // a endpoint. (The subject is the endpoint.endpointState // map key) diff --git a/wgengine/magicsock/magicsock_test.go b/wgengine/magicsock/magicsock_test.go index 0872c9c7c..f075a9063 100644 --- a/wgengine/magicsock/magicsock_test.go +++ b/wgengine/magicsock/magicsock_test.go @@ -743,6 +743,18 @@ func TestActiveDiscovery(t *testing.T) { testActiveDiscovery(t, n) }) + // The following tests lose a disco pong before establishing a + // direct connection, so instead of waiting 5 seconds in the + // test, reduce the wait period. + origPingTimeoutDuration := pingTimeoutDuration + origDiscoPingInterval := discoPingInterval + discoPingInterval = 100 * time.Millisecond + pingTimeoutDuration = 100 * time.Millisecond + defer func() { + pingTimeoutDuration = origPingTimeoutDuration + discoPingInterval = origDiscoPingInterval + }() + t.Run("facing_easy_firewalls", func(t *testing.T) { mstun := &natlab.Machine{Name: "stun"} m1 := &natlab.Machine{