| 1 | package host |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/carlosframework/platform/internal/hostclaim" |
| 7 | ) |
| 8 | |
| 9 | // M9: an admitted wake attempt keeps its writer only across adjacent forward |
| 10 | // steps it has checked. Its checkpoint advances on each one; a skipped step |
| 11 | // or a step back from the checkpoint refuses and leaves it unchanged. |
| 12 | func TestPlan9Fix1WakeAttemptAdvancesOneCheckedStepAtATime(t *testing.T) { |
| 13 | probing := plan9D1Session(hostclaim.PhaseLandingProbing, 11) |
| 14 | probed := plan9D1Session(hostclaim.PhaseLandingProbed, 11) |
| 15 | committed := plan9D1Session(hostclaim.PhaseLandingCommitted, 11) |
| 16 | |
| 17 | skip := &claimWakeAttempt{observed: probing} |
| 18 | if skip.advance(committed, hostclaim.SessionContinues) { |
| 19 | t.Fatal("probing advanced straight to committed") |
| 20 | } |
| 21 | if got, _ := skip.snapshot(); got.Claim.Op.Phase != hostclaim.PhaseLandingProbing { |
| 22 | t.Fatalf("a refused step moved the checkpoint to %q", got.Claim.Op.Phase) |
| 23 | } |
| 24 | |
| 25 | a := &claimWakeAttempt{observed: probing} |
| 26 | if !a.advance(probed, hostclaim.SessionContinues) || !a.advance(committed, hostclaim.SessionContinues) { |
| 27 | t.Fatal("checked adjacent steps ended the session") |
| 28 | } |
| 29 | if a.advance(probed, hostclaim.SessionContinues) || a.advance(probing, hostclaim.SessionContinues) { |
| 30 | t.Fatal("a step back from the checkpoint kept the session") |
| 31 | } |
| 32 | if !a.advance(committed, hostclaim.SessionContinues) { |
| 33 | t.Fatal("the checkpoint's own phase ended the session") |
| 34 | } |
| 35 | if a.advance(plan9D1Session(hostclaim.PhaseLandingCommitted, 12), hostclaim.SessionContinues) { |
| 36 | t.Fatal("a new session kept the checkpoint") |
| 37 | } |
| 38 | } |
| 39 | |