| index a5559b936..4d6d03cec 100644 |
| --- a/internal/host/movesphase1_test.go |
| +++ b/internal/host/movesphase1_test.go |
| @@ -428,27 +428,52 @@ func TestPreparingTouchesTheTargetRegionAndBoxFirst(t *testing.T) { |
| // A failed copy is retried only by calling again: the lane asks the guard |
| // again before the retry, and a lease past the bound by then ends the round |
| // with no second request. |
| +// |
| +// A round's copies run side by side (lease.MirrorPrefixKeep), so the test |
| +// pins nothing to their order. The lease is cut short when the lane |
| +// announces its retry, after every copy of the first round has returned: |
| +// cutting it from inside the failing copy raced the sibling copy, which |
| +// could pass its guard first (a second request, CI 2026-10-27) or be |
| +// refused first (the round ending on the refusal with no retry). And the |
| +// retry is told apart per object: only the object whose copy failed is |
| +// sure to be copied again. |
| func TestStagingWriterRetriesWithANewCheck(t *testing.T) { |
| h := newPhase1Harness(t) |
| h.start(t, "manual") |
| // The first copy fails, and by its retry the lease is too close to |
| - // its end. |
| - copies := 0 |
| + // its end. failAt runs under the fake's lock, and so does the |
| + // announcement's read of failedKey. |
| + copied := map[string]int{} |
| + failedKey, announced, afterRetry := "", false, 0 |
| h.f.failAt = func(op, key string) error { |
| if op != "copy" { |
| return nil |
| } |
| - copies++ |
| - if copies == 1 { |
| - h.lease.until = h.clock.now.Add(time.Minute) |
| + copied[key]++ |
| + if announced { |
| + afterRetry++ |
| + } |
| + if failedKey == "" { |
| + failedKey = key |
| return errors.New("injected 503") |
| } |
| return nil |
| } |
| - logs := captureLog(t) |
| + logs := captureLogThen(t, "retrying once", func() { |
| + h.f.mu.Lock() |
| + announced = true |
| + h.f.mu.Unlock() |
| + safe := h.clock.Now().Add(time.Minute) |
| + h.lease.mu.Lock() |
| + h.lease.until = safe |
| + h.lease.mu.Unlock() |
| + }) |
| h.pass(t) |
| - if copies != 1 { |
| - t.Fatalf("%d copy requests reached the store, want 1", copies) |
| + if failedKey == "" { |
| + t.Fatal("no copy request reached the store") |
| + } |
| + if copied[failedKey] != 1 || afterRetry != 0 { |
| + t.Fatalf("the failed object was requested %d times, %d requests after the retry was announced; want 1 and 0 (%v)", copied[failedKey], afterRetry, copied) |
| } |
| if !strings.Contains(logs(), "retrying once") || !strings.Contains(logs(), moves.ErrLeaseUnsafe.Error()) { |
| t.Fatalf("the retry did not go back to the guard:\n%s", logs()) |
| @@ -457,23 +482,23 @@ func TestStagingWriterRetriesWithANewCheck(t *testing.T) { |
| // With the lease safe, the retry's request is signed at a new check. |
| h2 := newPhase1Harness(t) |
| h2.start(t, "manual") |
| - var signs []time.Time |
| - failed := false |
| + var failedAt string |
| + signs := map[string][]time.Time{} |
| h2.f.failAt = func(op, key string) error { |
| if op != "copy" { |
| return nil |
| } |
| calls := h2.f.at |
| - signs = append(signs, calls[len(calls)-1].SignAt) |
| - if !failed { |
| - failed = true |
| + signs[key] = append(signs[key], calls[len(calls)-1].SignAt) |
| + if failedAt == "" { |
| + failedAt = key |
| return errors.New("injected 503") |
| } |
| return nil |
| } |
| h2.pass(t) |
| - if len(signs) < 2 || !signs[1].After(signs[0]) { |
| - t.Fatalf("the retry reused the first signature time: %v", signs) |
| + if s := signs[failedAt]; len(s) < 2 || !s[1].After(s[0]) { |
| + t.Fatalf("the retry of %s reused the first signature time: %v", failedAt, s) |
| } |
| } |
| |