S2 take once: keep the ids a holder took in its state taken
A holder of a kept call takes an ask once by its id: TakeOnce creates <seat>.<ask> in the state taken with the ask's bound as its time to live, and a second ask of the same id within it answers false. Builds: design 47 H2 §775, §820; H-A-338 (6), H-A-339 (4)
This commit is contained in:
@@ -227,6 +227,29 @@ func TestStatePutWritesAKeyWhole(t *testing.T) {
|
||||
if rev, err := dark.Put("k", 1); err != nil || rev == 0 || blackedOut != 0 {
|
||||
t.Fatalf("a Put through a short blackout: %d, %v", rev, err)
|
||||
}
|
||||
// Design 47 H2 §775: a holder given the same ask id twice acts once; the id is kept under <seat>.<ask> with the
|
||||
// ask's bound as its time to live; an ask with no id, or one that is not one key, is refused.
|
||||
tkv := newFakeKV()
|
||||
taken := stateOn(tkv)
|
||||
acts := 0
|
||||
for range 2 {
|
||||
if first, err := taken.TakeOnce("mesh-builds", "a-7", 10*time.Minute); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if first {
|
||||
acts++
|
||||
}
|
||||
}
|
||||
if acts != 1 || !tkv.withTTL[TakenKey("mesh-builds", "a-7")] || TakenKey("mesh-builds", "a-7") != "mesh-builds.a-7" {
|
||||
t.Fatalf("acted %d times, keys with a TTL %v", acts, tkv.withTTL)
|
||||
}
|
||||
if first, err := taken.TakeOnce("mesh-wants", "a-7", time.Minute); !first || err != nil {
|
||||
t.Fatalf("the same id on another seat is another ask: %v, %v", first, err)
|
||||
}
|
||||
for _, bad := range [][2]string{{"mesh-builds", ""}, {"mesh-builds", "a.7"}, {"", "a-8"}} {
|
||||
if _, err := taken.TakeOnce(bad[0], bad[1], time.Minute); err == nil {
|
||||
t.Errorf("seat %q, ask %q was taken", bad[0], bad[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 1840/S1: given a state, when its keys are listed, then they come sorted, and none is an empty list, not an error.
|
||||
|
||||
Reference in New Issue
Block a user