mirror of https://github.com/status-im/consul.git
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.
This commit is contained in:
parent
3a4e62836b
commit
1912c5ad89
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue