Skip to content

Commit 5635d9d

Browse files
committed
test(postgres): pin that a rollout dated by the attach record runs out
The deadline tests dated every rollout by the job's own condition, so a change that let a rollout dated by the Cluster's attach record wait forever would have passed them. Assisted-by: LLM Signed-off-by: Alexey Artamonov <[email protected]>
1 parent a27de05 commit 5635d9d

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

‎internal/backupcontroller/cnpgstrategy_controller_test.go‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2887,6 +2887,36 @@ func TestReconcileCNPG_PluginRolloutDeadlineCountsFromAttach(t *testing.T) {
28872887
}
28882888
}
28892889

2890+
// A rollout dated by the Cluster's attach record runs out like one dated by
2891+
// the job's own condition: a record newer than the condition but older than
2892+
// the deadline fails the job too.
2893+
func TestReconcileCNPG_PluginRolloutDeadlineCountsFromTheAttachRecord(t *testing.T) {
2894+
expired := time.Now().Add(-(cnpgDefaultBackupDeadline + time.Minute)).Truncate(time.Second)
2895+
f := newCNPGRolloutFixture(t, newRolloutBackupJob(expired.Add(-time.Hour)),
2896+
newRolloutCluster(cnpgClusterHealthyPhase), newRolloutInstancePod(expired.Add(-time.Hour)))
2897+
2898+
j, _ := f.pass() // latch
2899+
latch := apimeta.FindStatusCondition(j.Status.Conditions, backupCondPluginRolledOut)
2900+
if latch == nil {
2901+
t.Fatalf("no %s latch: %+v", backupCondPluginRolledOut, j.Status.Conditions)
2902+
}
2903+
latch.LastTransitionTime = metav1.NewTime(expired.Add(-10 * time.Minute))
2904+
if err := f.c.Status().Update(context.Background(), j); err != nil {
2905+
t.Fatalf("age the latch: %v", err)
2906+
}
2907+
live := newRolloutCluster(cnpgClusterHealthyPhase, buildBarmanPlugin(rolloutCluster, rolloutCluster))
2908+
live.Annotations = map[string]string{cnpgPluginAttachedAtAnnotation: expired.UTC().Format(time.RFC3339)}
2909+
f.observeCNPG(live)
2910+
2911+
j, backups := f.pass()
2912+
if len(backups) != 0 {
2913+
t.Fatalf("a cnpg.io/Backup was created against an instance older than the attach: %+v", backups)
2914+
}
2915+
if j.Status.Phase != backupsv1alpha1.BackupJobPhaseFailed || !strings.Contains(j.Status.Message, "rollout did not finish") {
2916+
t.Fatalf("phase = %q (%s), want Failed on a rollout recorded longer ago than the deadline", j.Status.Phase, j.Status.Message)
2917+
}
2918+
}
2919+
28902920
// The rollout is measured from the write that attached the plugin, not from
28912921
// the latch recorded before it: retries of a failing write can lie between
28922922
// the two, and an instance recreated in that time runs without the plugin.

0 commit comments

Comments
 (0)