From c3958898f11945398ae6d9eb25d5f989e33fefc0 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 27 Jul 2020 19:46:34 +0000 Subject: [PATCH] tstest/natlab: be a bit more lenient during test shutdown. There is a race in natlab where we might start shutdown while natlab is still running a goroutine or two to deliver packets. This adds a small grace period to try and receive it before continuing shutdown. Signed-off-by: David Anderson --- wgengine/magicsock/magicsock_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/wgengine/magicsock/magicsock_test.go b/wgengine/magicsock/magicsock_test.go index c433b8eec..00af5e142 100644 --- a/wgengine/magicsock/magicsock_test.go +++ b/wgengine/magicsock/magicsock_test.go @@ -732,6 +732,14 @@ func newPinger(t *testing.T, logf logger.Logf, srcM, dstM *magicStack, srcIP, ds t.Errorf("timed out waiting for ping to transit") return true case <-ctx.Done(): + // Try a little bit longer to consume the packet we're + // waiting for. This is to deal with shutdown races, where + // natlab may still be delivering a packet to us from a + // goroutine. + select { + case <-dstM.tun.Inbound: + case <-time.After(time.Second): + } return false } } @@ -763,7 +771,6 @@ func testActiveDiscovery(t *testing.T, d *devices) { tstest.PanicOnLog() rc := tstest.NewResourceCheck() defer rc.Assert(t) - defer natlab.WaitIdle() tlogf, setT := makeNestable(t) setT(t)