Skip to content

Commit a62a081

Browse files
authored
[chore] Fix flaky Prometheus watcher test (#2643)
The test was calling an assert inside an Eventually callback, which in essence meant it only ever tried once. I changed it into an explicit timed wait on a channel.
1 parent d190a3e commit a62a081

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

cmd/otel-allocator/watcher/promOperator_test.go

+15-17
Original file line numberDiff line numberDiff line change
@@ -902,25 +902,23 @@ func TestNamespaceLabelUpdate(t *testing.T) {
902902
sanitizeScrapeConfigsForTest(got.ScrapeConfigs)
903903
assert.Equal(t, want_before.ScrapeConfigs, got.ScrapeConfigs)
904904

905-
require.Eventually(t, func() bool {
906-
source.Modify(&v1.Namespace{ObjectMeta: metav1.ObjectMeta{
907-
Name: "labellednamespace",
908-
Labels: map[string]string{
909-
"label2": "label2",
910-
},
911-
}})
905+
source.Modify(&v1.Namespace{ObjectMeta: metav1.ObjectMeta{
906+
Name: "labellednamespace",
907+
Labels: map[string]string{
908+
"label2": "label2",
909+
},
910+
}})
912911

913-
select {
914-
case <-events:
915-
got, err := w.LoadConfig(context.Background())
916-
assert.NoError(t, err)
912+
select {
913+
case <-events:
914+
case <-time.After(time.Second):
915+
}
917916

918-
sanitizeScrapeConfigsForTest(got.ScrapeConfigs)
919-
return assert.Equal(t, want_after.ScrapeConfigs, got.ScrapeConfigs)
920-
default:
921-
return false
922-
}
923-
}, time.Second, time.Millisecond)
917+
got, err = w.LoadConfig(context.Background())
918+
assert.NoError(t, err)
919+
920+
sanitizeScrapeConfigsForTest(got.ScrapeConfigs)
921+
assert.Equal(t, want_after.ScrapeConfigs, got.ScrapeConfigs)
924922
}
925923

926924
func TestRateLimit(t *testing.T) {

0 commit comments

Comments
 (0)