H-A-458 (3): bind the taken write by the compose call's own context

The state taken's write was bound by a five-second bound of its own,
whatever the ask's deadline, so an ask whose caller had gone could still be
kept, and its repeat refused. takenWithin goes: Env.Taken carries the
compose call's context, Session.TakeOnce binds the state with it and keeps
nothing once it ended. Row: a take whose context ended is refused, and the
same id is then taken the first time.

Review round 1, finding: the taken bound.

Builds: design 47 H2 §775; H-A-364 (a), H-A-458 (3)
This commit is contained in:
2026-11-22 02:57:45 +01:00
parent 7d87dde0a4
commit 213542192c
5 changed files with 22 additions and 12 deletions
+11 -1
View File
@@ -138,10 +138,20 @@ func TestNatsTheRecoveryStepAsksHearsBoundsAndCatchesUpOverTheBus(t *testing.T)
// Design 47 H2 §775, H-A-364: over the same session, an ask of the seat is taken once in the state taken: the first time,
// and never again within its bound.
for i, want := range []bool{true, false} {
if took, err := session.TakeOnce(nodeengine.Seat, "ask-1", time.Minute); err != nil || took != want {
if took, err := session.TakeOnce(ctx, nodeengine.Seat, "ask-1", time.Minute); err != nil || took != want {
t.Fatalf("take %d of ask-1: %v, %v; want %v", i+1, took, err, want)
}
}
// H-A-458 (3): the write is bound by the ask's own context: an ask whose context ended keeps nothing, so the same id is
// taken the first time once asked again within a live one.
gone, end := context.WithCancel(ctx)
end()
if took, err := session.TakeOnce(gone, nodeengine.Seat, "ask-2", time.Minute); err == nil || took {
t.Fatalf("a take of ask-2 whose context ended: %v, %v; want refused", took, err)
}
if took, err := session.TakeOnce(ctx, nodeengine.Seat, "ask-2", time.Minute); err != nil || !took {
t.Fatalf("ask-2 asked again within a live context: %v, %v; want taken the first time", took, err)
}
events, stop, err := r.Hear(ctx, "restored", "db", "cache")
if err != nil {