Skip to content

Commit 2dcc2ef

Browse files
authored
Fix slow unit tests (#3191)
1 parent 22b9e30 commit 2dcc2ef

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

pkg-new/upgrade/upgrade.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,13 @@ func createAutopilotPlan(ctx context.Context, cli client.Client, rc runtimeconfi
368368
}
369369

370370
func waitForAutopilotPlan(ctx context.Context, cli client.Client, logger logrus.FieldLogger) (apv1b2.Plan, error) {
371-
backoff := wait.Backoff{
371+
return waitForAutopilotPlanWithBackoff(ctx, cli, logger, wait.Backoff{
372372
Duration: 20 * time.Second, // 20-second polling interval
373373
Steps: 90, // 90 attempts × 20s = 1800s = 30 minutes
374-
}
374+
})
375+
}
375376

377+
func waitForAutopilotPlanWithBackoff(ctx context.Context, cli client.Client, logger logrus.FieldLogger, backoff wait.Backoff) (apv1b2.Plan, error) {
376378
var plan apv1b2.Plan
377379
var lastErr error
378380

pkg-new/upgrade/upgrade_test.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,10 @@ func TestWaitForAutopilotPlan_RetriesOnTransientErrors(t *testing.T) {
428428
currentCount: &callCount,
429429
}
430430

431-
result, err := waitForAutopilotPlan(t.Context(), cli, logger)
431+
result, err := waitForAutopilotPlanWithBackoff(t.Context(), cli, logger, wait.Backoff{
432+
Duration: 1 * time.Millisecond,
433+
Steps: 10,
434+
})
432435
require.NoError(t, err)
433436
assert.Equal(t, "autopilot", result.Name)
434437
assert.Equal(t, int32(4), callCount.Load(), "Should have retried 3 times before succeeding")
@@ -477,7 +480,10 @@ func TestWaitForAutopilotPlan_WaitsForCompletion(t *testing.T) {
477480
callsUntil: 3, // Will complete after 3 calls
478481
}
479482

480-
result, err := waitForAutopilotPlan(t.Context(), cli, logger)
483+
result, err := waitForAutopilotPlanWithBackoff(t.Context(), cli, logger, wait.Backoff{
484+
Duration: 1 * time.Millisecond,
485+
Steps: 10,
486+
})
481487
require.NoError(t, err)
482488
assert.Equal(t, "autopilot", result.Name)
483489
assert.Equal(t, core.PlanCompleted, result.Status.State)
@@ -510,7 +516,10 @@ func TestWaitForAutopilotPlan_LongRunningUpgrade(t *testing.T) {
510516
callsUntil: 10, // Will complete after 10 calls - exceeds buggy 5-attempt limit
511517
}
512518

513-
result, err := waitForAutopilotPlan(t.Context(), cli, logger)
519+
result, err := waitForAutopilotPlanWithBackoff(t.Context(), cli, logger, wait.Backoff{
520+
Duration: 1 * time.Millisecond,
521+
Steps: 20,
522+
})
514523
require.NoError(t, err, "Should not timeout for long-running upgrades")
515524
assert.Equal(t, "autopilot", result.Name)
516525
assert.Equal(t, core.PlanCompleted, result.Status.State)
@@ -624,6 +633,10 @@ func TestWaitForClusterNodesMatchVersion(t *testing.T) {
624633
initialVersion: "v1.29.0+k0s",
625634
}
626635
},
636+
backoff: &wait.Backoff{
637+
Duration: 1 * time.Millisecond,
638+
Steps: 10,
639+
},
627640
expectError: false,
628641
validate: func(t *testing.T, cli client.Client) {
629642
if mock, ok := cli.(*mockClientWithNodeVersionUpdate); ok {
@@ -668,6 +681,10 @@ func TestWaitForClusterNodesMatchVersion(t *testing.T) {
668681
targetVersion: "v1.30.0+k0s",
669682
}
670683
},
684+
backoff: &wait.Backoff{
685+
Duration: 1 * time.Millisecond,
686+
Steps: 20,
687+
},
671688
expectError: false,
672689
validate: func(t *testing.T, cli client.Client) {
673690
if mock, ok := cli.(*mockClientWithStaggeredNodeUpdates); ok {
@@ -696,8 +713,6 @@ func TestWaitForClusterNodesMatchVersion(t *testing.T) {
696713
backoff: &wait.Backoff{
697714
Duration: 100 * time.Millisecond,
698715
Steps: 3,
699-
Factor: 1.0,
700-
Jitter: 0.1,
701716
},
702717
expectError: true,
703718
errorContains: "cluster nodes did not match version v1.30.0+k0s after upgrade",

0 commit comments

Comments
 (0)