diff --git a/command/agent/metrics_endpoint_test.go b/command/agent/metrics_endpoint_test.go index 0f1c04828..3d8d3a1db 100644 --- a/command/agent/metrics_endpoint_test.go +++ b/command/agent/metrics_endpoint_test.go @@ -6,6 +6,7 @@ import ( "testing" metrics "github.com/armon/go-metrics" + "github.com/hashicorp/nomad/testutil" "github.com/stretchr/testify/assert" ) @@ -41,12 +42,17 @@ func TestHTTP_Metrics(t *testing.T) { assert.Nil(err) respW = httptest.NewRecorder() - resp, err := s.Server.MetricsRequest(respW, req) - assert.Nil(err) + testutil.WaitForResult(func() (bool, error) { + resp, err := s.Server.MetricsRequest(respW, req) + if err != nil { + return false, err + } + respW.Flush() - res := resp.(metrics.MetricsSummary) - - gauges := res.Gauges - assert.NotEqual(0, len(gauges)) + res := resp.(metrics.MetricsSummary) + return len(res.Gauges) != 0, nil + }, func(err error) { + t.Fatalf("should have metrics: %v", err) + }) }) }