Skip to content

Commit 8de23cc

Browse files
authored
Fix flaky target allocator test (#3355)
The test involves measuring the rate limit for the Prometheus CR watcher , which is difficult to do given the potential timing differences between hosts. I basically just relaxed a lot of the checks - the test now passes if we take a lot longer than expected, and the tested interval is also larger to begin with.
1 parent ebabba3 commit 8de23cc

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

cmd/otel-allocator/watcher/promOperator_test.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ func TestRateLimit(t *testing.T) {
973973
},
974974
}
975975
events := make(chan Event, 1)
976-
eventInterval := 5 * time.Millisecond
976+
eventInterval := 500 * time.Millisecond
977977
cfg := allocatorconfig.Config{}
978978

979979
w, _ := getTestPrometheusCRWatcher(t, nil, nil, cfg)
@@ -1006,10 +1006,10 @@ func TestRateLimit(t *testing.T) {
10061006
default:
10071007
return false
10081008
}
1009-
}, eventInterval*2, time.Millisecond)
1009+
}, time.Second*5, eventInterval/10)
10101010

10111011
// it's difficult to measure the rate precisely
1012-
// what we do, is send two updates, and then assert that the elapsed time is between eventInterval and 3*eventInterval
1012+
// what we do, is send two updates, and then assert that the elapsed time is at least eventInterval
10131013
startTime := time.Now()
10141014
_, err = w.kubeMonitoringClient.MonitoringV1().ServiceMonitors("test").Update(context.Background(), serviceMonitor, metav1.UpdateOptions{})
10151015
require.NoError(t, err)
@@ -1020,7 +1020,7 @@ func TestRateLimit(t *testing.T) {
10201020
default:
10211021
return false
10221022
}
1023-
}, eventInterval*2, time.Millisecond)
1023+
}, time.Second*5, eventInterval/10)
10241024
_, err = w.kubeMonitoringClient.MonitoringV1().ServiceMonitors("test").Update(context.Background(), serviceMonitor, metav1.UpdateOptions{})
10251025
require.NoError(t, err)
10261026
require.Eventually(t, func() bool {
@@ -1030,11 +1030,9 @@ func TestRateLimit(t *testing.T) {
10301030
default:
10311031
return false
10321032
}
1033-
}, eventInterval*2, time.Millisecond)
1033+
}, time.Second*5, eventInterval/10)
10341034
elapsedTime := time.Since(startTime)
10351035
assert.Less(t, eventInterval, elapsedTime)
1036-
assert.GreaterOrEqual(t, eventInterval*3, elapsedTime)
1037-
10381036
}
10391037

10401038
// getTestPrometheusCRWatcher creates a test instance of PrometheusCRWatcher with fake clients

0 commit comments

Comments
 (0)