From 3552d8652553fbe7e73f998652f81aa05d30d0c9 Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Tue, 19 Oct 2021 05:10:38 -0700 Subject: [PATCH] wgengine/magicsock: turn down timeouts in tests Before: --- PASS: TestActiveDiscovery (11.78s) --- PASS: TestActiveDiscovery/facing_easy_firewalls (5.89s) --- PASS: TestActiveDiscovery/facing_nats (5.89s) --- PASS: TestActiveDiscovery/simple_internet (0.89s) After: --- PASS: TestActiveDiscovery (1.98s) --- PASS: TestActiveDiscovery/facing_easy_firewalls (0.99s) --- PASS: TestActiveDiscovery/facing_nats (0.99s) --- PASS: TestActiveDiscovery/simple_internet (0.89s) Signed-off-by: David Crawshaw --- wgengine/magicsock/magicsock.go | 23 +++++++++++++---------- wgengine/magicsock/magicsock_test.go | 12 ++++++++++++ 2 files changed, 25 insertions(+), 10 deletions(-) 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{