carlos / platform Public

lease: refuse only the drain snapshot in the WAL-release test (#810)

TestDrainReleaseSnapshotEarlyRefusalReleasesTheWAL failed on main
(63706d9c): its fake refused every level-9 write, including the store
monitor's Open-time snapshot, and litestream's DB.Snapshot leaves its
reader and the WAL open when an upload fails (#811). The test now marks
the drain release's context and the fake refuses only that snapshot.
The drain release itself frees the WAL in about 1.5 ms. #802 was not the
cause. Test-only change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Squashed from fix-wal-test-810 into main.
claude agent, operated by paul@keymail.dev c20838965766f5d67e4f0806aa8f2545d2e61fc7 parent 63706d9
1 file changed, +13 −2
  • internal/lease/release_snapshot_test.go +13 −2

CI passed — run details

diff --git a/internal/lease/release_snapshot_test.go b/internal/lease/release_snapshot_test.go
index a0228bc3c..3b2cafd61 100644
--- a/internal/lease/release_snapshot_test.go
+++ b/internal/lease/release_snapshot_test.go
@@ -29,6 +29,10 @@ import (
// countingReplica is a replica client that counts the LTX files opened
// (a restore's reads, one GET each on S3) and records the levels written,
// and can refuse snapshot writes.
+// drainSnapshotOnly marks the context of the drain release's own snapshot,
+// so a refusing fake can refuse that snapshot and no other.
+type drainSnapshotOnly struct{}
+
type countingReplica struct {
litestream.ReplicaClient
mu sync.Mutex
@@ -52,7 +56,12 @@ func (c *countingReplica) WriteLTXFile(ctx context.Context, level int, minTXID,
c.mu.Lock()
c.writes = append(c.writes, level)
fail := c.failSnapshot && level == litestream.SnapshotLevel
- early := c.refuseEarly && level == litestream.SnapshotLevel
+ // Only the drain's own snapshot is refused: the test marks its context
+ // (drainSnapshotOnly). The store monitor's snapshots run on the store's
+ // context and are never refused, so litestream's DB.Snapshot, which
+ // leaves its reader and the WAL open when an upload fails (#810, #811),
+ // never runs into this fake's refusal.
+ early := c.refuseEarly && level == litestream.SnapshotLevel && ctx.Value(drainSnapshotOnly{}) != nil
if level == litestream.SnapshotLevel {
c.snapshotTXID = maxTXID
}
@@ -230,7 +239,9 @@ func TestDrainReleaseSnapshotEarlyRefusalReleasesTheWAL(t *testing.T) {
dir := t.TempDir()
rc := &countingReplica{ReplicaClient: lsfile.NewReplicaClient(dir), refuseEarly: true}
r, path := manyL0(t, fx, "instances/h", rc, 5)
- txid, snapErr, err := r.FinishSnapshot(ctx)
+ // The refusal applies to the drain's own snapshot only (#810): its
+ // context carries drainSnapshotOnly, the store monitor's does not.
+ txid, snapErr, err := r.FinishSnapshot(context.WithValue(ctx, drainSnapshotOnly{}, true))
if err != nil || snapErr == nil {
t.Fatalf("FinishSnapshot: txid %d, snapshot %v, %v; want the snapshot's failure alone", txid, snapErr, err)
}