fix(test): adapt watermark-throttle test to #7044's single pre-sync read (#7219)

TestMaybeAutoBackup_WalkErrorArmsIntervalThrottle pinned the walk-error
re-arm in maybeAutoBackup by forcing runBackupExport's old post-sync
GetCurrentCommit call to fail. #7044 (874e2866f) collapsed that into a
single pre-sync CurrentCommit read, so the forced failure point no
longer exists and the test failed deterministically on every run.

Swap the failure point for one that still exists after #7044: the sync
itself succeeds (still proving fail-open — BackupDatabase gets called),
but the destination goes read-only immediately afterward, so
runBackupExport's post-sync saveBackupState (the call that would record
the new watermark) fails and never reaches disk. The only persisted
watermark write left standing is maybeAutoBackup's own walk-error
re-arm, so the test is still mutation-sensitive to removing it
(verified locally: deleting the re-arm reproduces the old failure).

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Julian Knutsen 2026-10-04 21:07:11 -07:00 • committed by GitHub
commit 298e08c1ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -765,39 +765,42 @@ func TestSizeCapStatus_UnavailableOnWalkError(t *testing.T) {
}
}
// postSyncCommitFailingStore syncs successfully but then fails the
// GetCurrentCommit that runBackupExport needs to record its watermark — one
// of the runBackupExport exits that returns without persisting state. Every
// other GetCurrentCommit (change detection) succeeds.
type postSyncCommitFailingStore struct {
// destinationGoesReadOnlyStore syncs successfully, but the destination
// loses write access the instant the sync finishes (e.g. a quota hit or a
// read-only remount mid-backup): BackupDatabase itself succeeds, so the
// sync genuinely happens, but it chmods dir read-only as a side effect, so
// runBackupExport's post-sync saveBackupState — the call that would record
// the new watermark — fails and never reaches disk. That is one of the
// runBackupExport exits that returns without persisting state; the single
// pre-sync GetCurrentCommit read (#7044) always succeeds here, so this
// isolates the write-failure exit rather than a commit-read failure.
type destinationGoesReadOnlyStore struct {
failingBackupStore
justSynced bool
t *testing.T
}
func (f *postSyncCommitFailingStore) BackupDatabase(ctx context.Context, dir string) error {
f.justSynced = true
return f.failingBackupStore.BackupDatabase(ctx, dir)
}
func (f *postSyncCommitFailingStore) GetCurrentCommit(context.Context) (string, error) {
if f.justSynced {
f.justSynced = false
return "", errors.New("dolt server unavailable")
func (f *destinationGoesReadOnlyStore) BackupDatabase(ctx context.Context, dir string) error {
if err := f.failingBackupStore.BackupDatabase(ctx, dir); err != nil {
return err
}
return f.commit, nil
if err := os.Chmod(dir, 0o500); err != nil {
f.t.Fatalf("chmod destination read-only: %v", err)
}
return nil
}
// TestMaybeAutoBackup_WalkErrorArmsIntervalThrottle pins the PR #6071
// iteration-2 review's behavioral minor: when the size-cap walk fails,
// maybeAutoBackup warns and proceeds uncapped, and it must re-arm the
// interval throttle itself before doing so. runBackupExport does not persist
// state.Timestamp on every exit — here the post-sync GetCurrentCommit fails
// after a successful sync — so without the re-arm the walk, its warning and
// the sync itself all repeat on every bd command instead of once per
// backup.interval.
// state.Timestamp on every exit — here the sync itself succeeds (proving
// fail-open) but the destination goes read-only immediately afterward, so
// the post-sync saveBackupState that would record the new watermark fails —
// so without the re-arm the walk, its warning and the sync itself all
// repeat on every bd command instead of once per backup.interval.
func TestMaybeAutoBackup_WalkErrorArmsIntervalThrottle(t *testing.T) {
if os.Geteuid() == 0 {
t.Skip("running as root; chmod does not deny reads")
t.Skip("running as root; chmod does not deny reads/writes")
}
t.Chdir(t.TempDir())
// The sync has to actually run for this test to reach runBackupExport's
@ -823,6 +826,7 @@ func TestMaybeAutoBackup_WalkErrorArmsIntervalThrottle(t *testing.T) {
if err != nil {
t.Fatalf("backupDir: %v", err)
}
t.Cleanup(func() { _ = os.Chmod(dir, 0o700) }) // undo the simulated read-only destination so t.TempDir() can clean up
// One unreadable entry inside an otherwise writable destination: the
// walk fails, but backup_state.json can still be read and written.
locked := filepath.Join(dir, "locked")
@ -838,7 +842,7 @@ func TestMaybeAutoBackup_WalkErrorArmsIntervalThrottle(t *testing.T) {
oldStore := store
// Different commit from the watermark ⇒ data changed ⇒ the walk runs.
fake := &postSyncCommitFailingStore{failingBackupStore: failingBackupStore{commit: "deadbeef"}}
fake := &destinationGoesReadOnlyStore{failingBackupStore: failingBackupStore{commit: "deadbeef"}, t: t}
store = fake
t.Cleanup(func() { store = oldStore })