From 66c787597461dd56ca8ec8c3b507cfc1420c4439 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 27 Apr 2020 23:01:06 -0700 Subject: [PATCH] control/controlclient: wait for c1 to receive a netmap. This strictly sequences things such that c1 is fully registered in the control server before c2 creates its poll. Failure to do this can cause an inversion where c2's poll finishes establishing before c1's poll starts, which results in c2 getting disconnected rather than c1, and the test times out waiting for c1 to get kicked. Fixes #98. Signed-off-by: David Anderson --- control/controlclient/direct_test.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/control/controlclient/direct_test.go b/control/controlclient/direct_test.go index 04d39c80a..a00342c22 100644 --- a/control/controlclient/direct_test.go +++ b/control/controlclient/direct_test.go @@ -94,15 +94,24 @@ func TestClientsReusingKeys(t *testing.T) { // test. We're expecting it to block happily, invoking the no-op // update function periodically, then exit once c2 starts its own // poll below. + gotNetmap := make(chan struct{}, 1) pollErrCh := make(chan error) go func() { - pollErrCh <- c1.PollNetMap(ctx, -1, func(netMap *NetworkMap) {}) + pollErrCh <- c1.PollNetMap(ctx, -1, func(netMap *NetworkMap) { + select { + case gotNetmap <- struct{}{}: + default: + } + }) }() select { + case <-gotNetmap: + t.Logf("c1: received initial netmap") case err := <-pollErrCh: t.Fatal(err) - default: + case <-time.After(5 * time.Second): + t.Fatal("c1 did not receive an initial netmap") } // Connect c2, reusing c1's credentials. In other words, c2 *is*