tests: read replica world lease time after the write (#511)
The replica world's coordinator exchange measured RemainingMS from a clock read before SetRecordCoordinator, which stamps ExpiresAt from its own later clock. Any write slower than 1 ms then reported more than the TTL left, and the client rightly fenced the acquire; CI hit it in TestReplicaReleaseTakeoverAdoptsDurableAttempt/pending. Read the clock after the write, as handleReplicaCoordinator does. A store with a 2 ms Get reproduced the fence before the change and passes after it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+6
−3
internal/activator/replicarelease_world_test.go+6 −3
Intent
Attributed to this commit: 50.3 g CO₂e (6,331,049 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on stateless-replicas-4, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/internal/activator/replicarelease_world_test.go b/internal/activator/replicarelease_world_test.go| index 7bea34d60..f43c91dd8 100644 |
| --- a/internal/activator/replicarelease_world_test.go |
| +++ b/internal/activator/replicarelease_world_test.go |
| @@ -121,12 +121,15 @@ func (in *replicaInstance) box(label, boot string) *replicaBox { |
| r.a.mu.Unlock() |
| } |
| exchange := func(ctx context.Context, id replicas.Identity, change replicas.CoordinatorChange) (replicas.CoordinatorReply, error) { |
| - now := w.now() |
| - rec, err := provision.SetRecordCoordinator(ctx, w.s, id, change, now) |
| + rec, err := provision.SetRecordCoordinator(ctx, w.s, id, change, w.now()) |
| if err != nil { |
| return replicas.CoordinatorReply{}, err |
| } |
| - return replicas.CoordinatorReply{Lease: *rec.Coordinator, RemainingMS: max(0, rec.Coordinator.ExpiresAt.Sub(now).Milliseconds())}, nil |
| + // Remaining is read after the write, as handleReplicaCoordinator |
| + // does: the writer stamps ExpiresAt from its own later clock, so |
| + // measuring from before the write overstates it by the write's |
| + // duration, and a slow write reads past the TTL and fences. |
| + return replicas.CoordinatorReply{Lease: *rec.Coordinator, RemainingMS: max(0, rec.Coordinator.ExpiresAt.Sub(w.now()).Milliseconds())}, nil |
| } |
| releaseState := func(ctx context.Context, id replicas.Identity, change replicas.ReleaseChange) (replicas.Deploy, error) { |
| current, err := provision.GetRecord(ctx, w.s, id.Account, id.App, id.Host) |