mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-13 13:55:41 +00:00
Pass context down to wait.PollUntilContextTimeout
This commit is contained in:
parent
6168143386
commit
42a5e5f425
@ -675,7 +675,7 @@ func findCpuUtilization(metricStatus []autoscalingv2.MetricStatus) (utilization
|
|||||||
return nil
|
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()
|
tc.Lock()
|
||||||
defer tc.Unlock()
|
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")
|
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.
|
// 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.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")
|
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 {
|
if !ok {
|
||||||
t.Fatalf("test HPA controller should have mockMonitor, but actually not")
|
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) {
|
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.
|
// waitUntilRecorded waits for the HPA controller to reconcile at least once.
|
||||||
func (m *mockMonitor) waitUntilRecorded(t *testing.T) {
|
func (m *mockMonitor) waitUntilRecorded(ctx context.Context, t *testing.T) {
|
||||||
if err := wait.PollUntilContextTimeout(context.Background(), 20*time.Millisecond, 100*time.Millisecond, true, func(ctx context.Context) (done bool, err error) {
|
if err := wait.PollUntilContextTimeout(ctx, 20*time.Millisecond, 100*time.Millisecond, true, func(ctx context.Context) (done bool, err error) {
|
||||||
m.RWMutex.RLock()
|
m.RWMutex.RLock()
|
||||||
defer m.RWMutex.RUnlock()
|
defer m.RWMutex.RUnlock()
|
||||||
if len(m.reconciliationActionLabels) == 0 || len(m.reconciliationErrorLabels) == 0 {
|
if len(m.reconciliationActionLabels) == 0 || len(m.reconciliationErrorLabels) == 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user