Pass context down to wait.PollUntilContextTimeout

This commit is contained in:
Adrian Moisey 2025-01-07 16:25:55 +02:00
parent 6168143386
commit 42a5e5f425
No known key found for this signature in database
GPG Key ID: 41AE4AE32747C7CF

View File

@ -675,7 +675,7 @@ func findCpuUtilization(metricStatus []autoscalingv2.MetricStatus) (utilization
return nil
}
func (tc *testCase) verifyResults(t *testing.T, m *mockMonitor) {
func (tc *testCase) verifyResults(ctx context.Context, t *testing.T, m *mockMonitor) {
tc.Lock()
defer tc.Unlock()
@ -685,12 +685,12 @@ func (tc *testCase) verifyResults(t *testing.T, m *mockMonitor) {
assert.Equal(t, tc.specReplicas != tc.expectedDesiredReplicas, tc.eventCreated, "an event should have been created only if we expected a change in replicas")
}
tc.verifyRecordedMetric(t, m)
tc.verifyRecordedMetric(ctx, t, m)
}
func (tc *testCase) verifyRecordedMetric(t *testing.T, m *mockMonitor) {
func (tc *testCase) verifyRecordedMetric(ctx context.Context, t *testing.T, m *mockMonitor) {
// First, wait for the reconciliation completed at least once.
m.waitUntilRecorded(t)
m.waitUntilRecorded(ctx, t)
assert.Equal(t, tc.expectedReportedReconciliationActionLabel, m.reconciliationActionLabels[0], "the reconciliation action should be recorded in monitor expectedly")
assert.Equal(t, tc.expectedReportedReconciliationErrorLabel, m.reconciliationErrorLabels[0], "the reconciliation error should be recorded in monitor expectedly")
@ -833,7 +833,7 @@ func (tc *testCase) runTestWithController(t *testing.T, hpaController *Horizonta
if !ok {
t.Fatalf("test HPA controller should have mockMonitor, but actually not")
}
tc.verifyResults(t, m)
tc.verifyResults(ctx, t, m)
}
func (tc *testCase) runTest(t *testing.T) {
@ -875,8 +875,8 @@ func (m *mockMonitor) ObserveMetricComputationResult(action monitor.ActionLabel,
}
// waitUntilRecorded waits for the HPA controller to reconcile at least once.
func (m *mockMonitor) waitUntilRecorded(t *testing.T) {
if err := wait.PollUntilContextTimeout(context.Background(), 20*time.Millisecond, 100*time.Millisecond, true, func(ctx context.Context) (done bool, err error) {
func (m *mockMonitor) waitUntilRecorded(ctx context.Context, t *testing.T) {
if err := wait.PollUntilContextTimeout(ctx, 20*time.Millisecond, 100*time.Millisecond, true, func(ctx context.Context) (done bool, err error) {
m.RWMutex.RLock()
defer m.RWMutex.RUnlock()
if len(m.reconciliationActionLabels) == 0 || len(m.reconciliationErrorLabels) == 0 {