diff --git a/receiver/kubeletstatsreceiver/scraper_test.go b/receiver/kubeletstatsreceiver/scraper_test.go index 0dc55e405cbd..2d0a344b5eb6 100644 --- a/receiver/kubeletstatsreceiver/scraper_test.go +++ b/receiver/kubeletstatsreceiver/scraper_test.go @@ -9,8 +9,10 @@ import ( "os" "path/filepath" "testing" + "time" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/receiver/receivertest" "go.uber.org/zap" "go.uber.org/zap/zaptest/observer" @@ -134,9 +136,14 @@ func TestScraperWithNodeUtilization(t *testing.T) { require.NoError(t, err) } - md, err := r.Scrape(context.Background()) - require.NoError(t, err) - require.Equal(t, numContainers+numPods, md.DataPointCount()) + var md pmetric.Metrics + require.Eventually(t, func() bool { + md, err = r.Scrape(context.Background()) + require.NoError(t, err) + return numContainers+numPods == md.DataPointCount() + }, 10*time.Second, 100*time.Millisecond, + "metrics not collected") + expectedFile := filepath.Join("testdata", "scraper", "test_scraper_cpu_util_nodelimit_expected.yaml") // Uncomment to regenerate '*_expected.yaml' files