Fix race issue in monitor endpoint test
This commit is contained in:
parent
33b29ccfd7
commit
3649c18ef0
|
@ -1,7 +1,6 @@
|
||||||
package agent
|
package agent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -1145,8 +1144,7 @@ func TestHTTPAgentRegisterServiceCheck(t *testing.T) {
|
||||||
|
|
||||||
func TestHTTPAgent_Monitor(t *testing.T) {
|
func TestHTTPAgent_Monitor(t *testing.T) {
|
||||||
logWriter := logger.NewLogWriter(512)
|
logWriter := logger.NewLogWriter(512)
|
||||||
expectedLogs := bytes.Buffer{}
|
logger := io.MultiWriter(os.Stdout, logWriter)
|
||||||
logger := io.MultiWriter(os.Stdout, &expectedLogs, logWriter)
|
|
||||||
|
|
||||||
dir, srv := makeHTTPServerWithConfigLog(t, nil, logger, logWriter)
|
dir, srv := makeHTTPServerWithConfigLog(t, nil, logger, logWriter)
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
@ -1206,21 +1204,21 @@ func TestHTTPAgent_Monitor(t *testing.T) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Verify that the first 5 logs we get match the expected stream
|
// Wait until we see the expected log line
|
||||||
for i := 0; i < 5; i++ {
|
expected := "raft: Initial configuration (index=1)"
|
||||||
|
testutil.WaitForResult(func() (bool, error) {
|
||||||
select {
|
select {
|
||||||
case log := <-logCh:
|
case log := <-logCh:
|
||||||
expected, err := expectedLogs.ReadString('\n')
|
if !strings.Contains(log, expected) {
|
||||||
if err != nil {
|
return false, fmt.Errorf("Log message does not match expected")
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
if log != expected {
|
|
||||||
t.Fatalf("bad: %q %q", expected, log)
|
|
||||||
}
|
}
|
||||||
case <-time.After(10 * time.Second):
|
case <-time.After(10 * time.Second):
|
||||||
t.Fatalf("failed to get log within timeout")
|
return false, fmt.Errorf("failed to get log within timeout")
|
||||||
}
|
}
|
||||||
}
|
return true, nil
|
||||||
|
}, func(err error) {
|
||||||
|
t.Fatal(err)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type closableRecorder struct {
|
type closableRecorder struct {
|
||||||
|
|
Loading…
Reference in New Issue