Skip to content

Commit 42a5e5f

Browse files
committed
Pass context down to wait.PollUntilContextTimeout
1 parent 6168143 commit 42a5e5f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

pkg/controller/podautoscaler/horizontal_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ func findCpuUtilization(metricStatus []autoscalingv2.MetricStatus) (utilization
675675
return nil
676676
}
677677

678-
func (tc *testCase) verifyResults(t *testing.T, m *mockMonitor) {
678+
func (tc *testCase) verifyResults(ctx context.Context, t *testing.T, m *mockMonitor) {
679679
tc.Lock()
680680
defer tc.Unlock()
681681

@@ -685,12 +685,12 @@ func (tc *testCase) verifyResults(t *testing.T, m *mockMonitor) {
685685
assert.Equal(t, tc.specReplicas != tc.expectedDesiredReplicas, tc.eventCreated, "an event should have been created only if we expected a change in replicas")
686686
}
687687

688-
tc.verifyRecordedMetric(t, m)
688+
tc.verifyRecordedMetric(ctx, t, m)
689689
}
690690

691-
func (tc *testCase) verifyRecordedMetric(t *testing.T, m *mockMonitor) {
691+
func (tc *testCase) verifyRecordedMetric(ctx context.Context, t *testing.T, m *mockMonitor) {
692692
// First, wait for the reconciliation completed at least once.
693-
m.waitUntilRecorded(t)
693+
m.waitUntilRecorded(ctx, t)
694694

695695
assert.Equal(t, tc.expectedReportedReconciliationActionLabel, m.reconciliationActionLabels[0], "the reconciliation action should be recorded in monitor expectedly")
696696
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
833833
if !ok {
834834
t.Fatalf("test HPA controller should have mockMonitor, but actually not")
835835
}
836-
tc.verifyResults(t, m)
836+
tc.verifyResults(ctx, t, m)
837837
}
838838

839839
func (tc *testCase) runTest(t *testing.T) {
@@ -875,8 +875,8 @@ func (m *mockMonitor) ObserveMetricComputationResult(action monitor.ActionLabel,
875875
}
876876

877877
// waitUntilRecorded waits for the HPA controller to reconcile at least once.
878-
func (m *mockMonitor) waitUntilRecorded(t *testing.T) {
879-
if err := wait.PollUntilContextTimeout(context.Background(), 20*time.Millisecond, 100*time.Millisecond, true, func(ctx context.Context) (done bool, err error) {
878+
func (m *mockMonitor) waitUntilRecorded(ctx context.Context, t *testing.T) {
879+
if err := wait.PollUntilContextTimeout(ctx, 20*time.Millisecond, 100*time.Millisecond, true, func(ctx context.Context) (done bool, err error) {
880880
m.RWMutex.RLock()
881881
defer m.RWMutex.RUnlock()
882882
if len(m.reconciliationActionLabels) == 0 || len(m.reconciliationErrorLabels) == 0 {

0 commit comments

Comments
 (0)