From 512a523a3e24b9a2b81ed19070e647206631dbff Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Thu, 13 Aug 2020 17:48:46 -0400 Subject: [PATCH] testing: wait until monitor has started before shutdown This commit fixes a test that I saw flake locally while running tests. The test output from the monitor started immediately after the line the test was looking for. To fix the problem a channel is closed when the goroutine starts. Shutdown is not called until this channel is closed, which seems to greatly reduce the chance of a flake. --- agent/agent_endpoint_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/agent/agent_endpoint_test.go b/agent/agent_endpoint_test.go index d7d8f94b4..6f2b9f7bf 100644 --- a/agent/agent_endpoint_test.go +++ b/agent/agent_endpoint_test.go @@ -4542,12 +4542,15 @@ func TestAgent_Monitor(t *testing.T) { req = req.WithContext(cancelCtx) resp := httptest.NewRecorder() - errCh := make(chan error) + chErr := make(chan error) + chStarted := make(chan struct{}) go func() { + close(chStarted) _, err := a.srv.AgentMonitor(resp, req) - errCh <- err + chErr <- err }() + <-chStarted require.NoError(t, a.Shutdown()) // Wait until we have received some type of logging output @@ -4556,7 +4559,7 @@ func TestAgent_Monitor(t *testing.T) { }, 3*time.Second, 100*time.Millisecond) cancelFunc() - err := <-errCh + err := <-chErr require.NoError(t, err) got := resp.Body.String()