Skip to content

Commit

Permalink
fix test to avoid race condition flakiness
Browse files Browse the repository at this point in the history
Signed-off-by: ChrsMark <[email protected]>
  • Loading branch information
ChrsMark committed Jun 25, 2024
1 parent ecffbc3 commit 2b853bd
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions receiver/kubeletstatsreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -208,9 +210,13 @@ func TestScraperWithMemoryNodeUtilization(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_memory_util_nodelimit_expected.yaml")

// Uncomment to regenerate '*_expected.yaml' files
Expand Down

0 comments on commit 2b853bd

Please sign in to comment.