Skip to content

Commit 9613fc3

Browse files
authored
Merge pull request #150987 from cockroachdb/blathers/backport-release-25.3-150950
release-25.3: backup: deflake some chaining tests
2 parents 48a9e8f + 435de93 commit 9613fc3

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

pkg/backup/create_scheduled_backup_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,14 @@ func (h *testHelper) setOverrideAsOfClauseKnob(t *testing.T) {
121121
// We'll be manipulating schedule time via th.env, but we can't fool actual
122122
// backup when it comes to AsOf time. So, override AsOf backup clause to be
123123
// the current time.
124-
h.cfg.TestingKnobs.(*jobs.TestingKnobs).OverrideAsOfClause = func(clause *tree.AsOfClause, _ time.Time) {
125-
expr, err := tree.MakeDTimestampTZ(h.cfg.DB.KV().Clock().PhysicalTime(), time.Microsecond)
124+
h.cfg.TestingKnobs.(*jobs.TestingKnobs).OverrideAsOfClause = func(clause *tree.AsOfClause, statementTime time.Time) {
125+
backupAsOfTime := h.cfg.DB.KV().Clock().PhysicalTime()
126+
if backupAsOfTime.After(statementTime) {
127+
// If the backupAsOfTime is after the statement time, then we use the
128+
// statement time to avoid "AOST in the future" errors.
129+
backupAsOfTime = statementTime
130+
}
131+
expr, err := tree.MakeDTimestampTZ(backupAsOfTime, time.Microsecond)
126132
require.NoError(t, err)
127133
clause.Expr = expr
128134
}

pkg/backup/schedule_pts_chaining_test.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,13 @@ INSERT INTO t values (1), (10), (100);
114114
`)
115115

116116
backupAsOfTimes := make([]time.Time, 0)
117-
th.cfg.TestingKnobs.(*jobs.TestingKnobs).OverrideAsOfClause = func(clause *tree.AsOfClause, _ time.Time) {
117+
th.cfg.TestingKnobs.(*jobs.TestingKnobs).OverrideAsOfClause = func(clause *tree.AsOfClause, statementTime time.Time) {
118118
backupAsOfTime := th.cfg.DB.KV().Clock().PhysicalTime()
119+
if backupAsOfTime.After(statementTime) {
120+
// If the backupAsOfTime is after the statement time, then we use the
121+
// statement time to avoid "AOST in the future" errors.
122+
backupAsOfTime = statementTime
123+
}
119124
expr, err := tree.MakeDTimestampTZ(backupAsOfTime, time.Microsecond)
120125
require.NoError(t, err)
121126
clause.Expr = expr
@@ -241,8 +246,13 @@ INSERT INTO t values (1), (10), (100);
241246
`)
242247

243248
backupAsOfTimes := make([]time.Time, 0)
244-
th.cfg.TestingKnobs.(*jobs.TestingKnobs).OverrideAsOfClause = func(clause *tree.AsOfClause, _ time.Time) {
249+
th.cfg.TestingKnobs.(*jobs.TestingKnobs).OverrideAsOfClause = func(clause *tree.AsOfClause, statementTime time.Time) {
245250
backupAsOfTime := th.cfg.DB.KV().Clock().PhysicalTime()
251+
if backupAsOfTime.After(statementTime) {
252+
// If the backupAsOfTime is after the statement time, then we use the
253+
// statement time to avoid "AOST in the future" errors.
254+
backupAsOfTime = statementTime
255+
}
246256
expr, err := tree.MakeDTimestampTZ(backupAsOfTime, time.Microsecond)
247257
require.NoError(t, err)
248258
clause.Expr = expr
@@ -336,8 +346,13 @@ INSERT INTO t values (1), (10), (100);
336346
`)
337347

338348
backupAsOfTimes := make([]time.Time, 0)
339-
th.cfg.TestingKnobs.(*jobs.TestingKnobs).OverrideAsOfClause = func(clause *tree.AsOfClause, _ time.Time) {
349+
th.cfg.TestingKnobs.(*jobs.TestingKnobs).OverrideAsOfClause = func(clause *tree.AsOfClause, statementTime time.Time) {
340350
backupAsOfTime := th.cfg.DB.KV().Clock().PhysicalTime()
351+
if backupAsOfTime.After(statementTime) {
352+
// If the backupAsOfTime is after the statement time, then we use the
353+
// statement time to avoid "AOST in the future" errors.
354+
backupAsOfTime = statementTime
355+
}
341356
expr, err := tree.MakeDTimestampTZ(backupAsOfTime, time.Microsecond)
342357
require.NoError(t, err)
343358
clause.Expr = expr

0 commit comments

Comments
 (0)