Skip to content

Commit 62c5cc6

Browse files
committed
test(postgres): pin the requeue and the read-only pass of a running backup
Three guards of the CNPG driver could be reverted with the package tests still green. The controller watches only BackupJobs, so a job waiting in the queue or retrying the destination write is woken by nothing but its own requeue, and the tests dropped the result. A job whose Backup runs must not consult the queue, or two jobs that passed it together wait on each other forever, and must patch neither the ObjectStore nor the Cluster plugin, yet only the ObjectStore content was checked. Assisted-by: LLM Signed-off-by: Alexey Artamonov <[email protected]>
1 parent d67bbf2 commit 62c5cc6

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

‎internal/backupcontroller/cnpgstrategy_controller_test.go‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2561,6 +2561,17 @@ func (f *cnpgRolloutFixture) seedOtherBackupJob(name string, phase backupsv1alph
25612561
func TestReconcileCNPG_RunningBackupDoesNotReapplyObjectStore(t *testing.T) {
25622562
f := newAttachedObjectStoreFixture(t, time.Now(), "s3://other/")
25632563
f.seedCNPGBackup("bj-cnpg", "bj", rolloutCluster, "running")
2564+
// Two jobs can pass the queue together, since it reads the cache; once
2565+
// both have a Backup neither may wait on the other.
2566+
f.seedOtherBackupJob("bj-other", backupsv1alpha1.BackupJobPhaseRunning)
2567+
f.seedCNPGBackup("bj-other-cnpg", "bj-other", rolloutCluster, "running")
2568+
writes := 0
2569+
f.r.Client = interceptor.NewClient(f.c.(client.WithWatch), interceptor.Funcs{
2570+
Patch: func(ctx context.Context, cl client.WithWatch, obj client.Object, patch client.Patch, opts ...client.PatchOption) error {
2571+
writes++
2572+
return cl.Patch(ctx, obj, patch, opts...)
2573+
},
2574+
})
25642575

25652576
j, _ := f.pass()
25662577
if j.Status.Phase == backupsv1alpha1.BackupJobPhaseFailed {
@@ -2569,8 +2580,11 @@ func TestReconcileCNPG_RunningBackupDoesNotReapplyObjectStore(t *testing.T) {
25692580
if got := f.liveDestination(); got != "s3://other/" {
25702581
t.Fatalf("a pass over a running backup re-applied the ObjectStore: destination %q", got)
25712582
}
2572-
if ready := apimeta.FindStatusCondition(j.Status.Conditions, "Ready"); ready != nil && ready.Reason == "WaitingForOtherBackup" {
2573-
t.Fatalf("a running backup waits on itself: %+v", ready)
2583+
if writes != 0 {
2584+
t.Errorf("a pass over a running backup patched %d object(s); the ObjectStore and the Cluster plugin are only read", writes)
2585+
}
2586+
if ready := apimeta.FindStatusCondition(j.Status.Conditions, "Ready"); ready == nil || ready.Reason != "WaitingForCNPGBackup" {
2587+
t.Fatalf("Ready = %+v, want the running backup followed rather than queued", ready)
25742588
}
25752589
}
25762590

@@ -2624,7 +2638,7 @@ func TestReconcileCNPG_WaitsForAnotherRunningBackupOfTheApp(t *testing.T) {
26242638
},
26252639
})
26262640

2627-
j, backups := f.pass()
2641+
j, backups, res := f.passResult()
26282642
if j.Status.Phase == backupsv1alpha1.BackupJobPhaseFailed {
26292643
t.Fatalf("BackupJob failed: %s", j.Status.Message)
26302644
}
@@ -2645,8 +2659,13 @@ func TestReconcileCNPG_WaitsForAnotherRunningBackupOfTheApp(t *testing.T) {
26452659
if ready == nil || ready.Status != metav1.ConditionFalse || ready.Reason != "WaitingForOtherBackup" || !strings.Contains(ready.Message, "bj-other") {
26462660
t.Errorf("Ready = %+v, want False/WaitingForOtherBackup naming bj-other", ready)
26472661
}
2662+
if res.RequeueAfter == 0 {
2663+
t.Errorf("a queued job is not requeued, and nothing else wakes it when the holder finishes: %+v", res)
2664+
}
26482665
statusWrites = 0
2649-
f.pass()
2666+
if _, _, res = f.passResult(); res.RequeueAfter == 0 {
2667+
t.Errorf("a queued job whose status did not change is not requeued: %+v", res)
2668+
}
26502669
if statusWrites != 0 {
26512670
t.Errorf("a second pass with the same holder wrote the BackupJob status %d time(s)", statusWrites)
26522671
}
@@ -2715,7 +2734,7 @@ func TestReconcileCNPG_ObjectStoreApplyErrors(t *testing.T) {
27152734
},
27162735
})
27172736

2718-
j, backups := f.pass()
2737+
j, backups, res := f.passResult()
27192738
if j.Status.Phase != tc.wantPhase {
27202739
t.Fatalf("BackupJob phase = %q (%s), want %q", j.Status.Phase, j.Status.Message, tc.wantPhase)
27212740
}
@@ -2727,6 +2746,9 @@ func TestReconcileCNPG_ObjectStoreApplyErrors(t *testing.T) {
27272746
if ready == nil || ready.Reason != "ClusterPluginApplyRetrying" || !strings.Contains(ready.Message, "connection refused") {
27282747
t.Errorf("Ready = %+v, want ClusterPluginApplyRetrying carrying the error", ready)
27292748
}
2749+
if res.RequeueAfter == 0 {
2750+
t.Errorf("a retried write is not requeued: %+v", res)
2751+
}
27302752
}
27312753
})
27322754
}

0 commit comments

Comments
 (0)