oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package mac
2
3import (
4 "os"
5 "testing"
6
7 "amadan.net/oficina/equipo/internal/runner/mac/proc"
8)
9
10// restarted is a new Turns over turns' lock and debts (a runner restart),
11// and an executor on it.
12func restarted(turns *Turns, x *Executor, tb Procs) (*Turns, *Executor) {
13 again := NewTurns(turns.lock).Sweep(tb)
14 again.own, again.Settle, again.boot = turns.own, turns.Settle, turns.boot
15 return again, &Executor{Turns: again, Settle: x.Settle}
16}
17
18// verifyAs is the proof a consumer's recovery asks for before it
19// commits what it found: a read, whoever asks.
20func verifyAs(x *Executor, id, _ string) bool { return x.Verify(id) }
21
22// Round 3, #1: proving a record after a reboot only reads its
23// completion. A consumer takes it by acknowledging, once its own result
24// is durable: a crash between the step's proof and its commit loses
25// nothing, though the Keychain recovery already took its share.
26func TestRebootCompletionSurvivesACrashBeforeTheCommit(t *testing.T) {
27 me := os.Getuid()
28 tb := parseTable(t, turnBegan)
29 turns, x, _, before := clearRig(t, tb, laterBoot, nil)
30 tb.add(row(99400, 1, 99400, 99400, 5000, me, ""), "/Users/paulequipo/w/this-boot")
31 if err := turns.debts.Owe(owed(before)); err != nil {
32 t.Fatal(err)
33 }
34 id := RecordID(99400, "attempt-c")
35 if !verifyAs(x, id, ConsumerKeychain) {
36 t.Fatal("the Keychain recovery's proof failed")
37 }
38 x.Acknowledge(id, ConsumerKeychain)
39 if !verifyAs(x, id, ConsumerStep) {
40 t.Fatal("the step recovery's proof failed")
41 }
42 // The runner dies before the step's transaction commits.
43 again, y := restarted(turns, x, tb)
44 if !y.Verify(id) {
45 t.Fatal("the step's proof was lost to a crash before its commit")
46 }
47 y.Acknowledge(id, ConsumerStep)
48 if again.debts.Owes("attempt-c") {
49 t.Fatal("the completion stayed after every consumer acknowledged it")
50 }
51 if sig := tb.signalled(); len(sig) != 0 {
52 t.Fatalf("signalled %v", sig)
53 }
54}
55
56// Round 3, #2: a reboot's evidence is per marker. Proving launch A of a
57// turn leaves launch B's evidence, so B, proven after a runner restart,
58// neither checks nor signals the old boot's group ids that this boot
59// reuses.
60func TestRebootEvidencePerMarker(t *testing.T) {
61 me := os.Getuid()
62 tb := parseTable(t, turnBegan)
63 turns, x, _, before := clearRig(t, tb, laterBoot, nil)
64 tb.add(row(99400, 1, 99400, 99400, 5000, me, ""), "/Users/paulequipo/w/this-boot")
65 tb.add(row(99401, 1, 99401, 99401, 5000, me, ""), "/Users/paulequipo/w/this-boot-too")
66 o := proc.Obligation{Markers: []string{"attempt-a", "attempt-b"}, Began: turnStart, BootID: "boot-1", Before: before, FlagsKnown: true, Groups: proc.Span{99400: 1, 99401: 1}}
67 if err := turns.debts.Owe(o); err != nil {
68 t.Fatal(err)
69 }
70 if !x.Verify(RecordID(99400, "attempt-a")) {
71 t.Fatal("A not proven by the reboot")
72 }
73 _, y := restarted(turns, x, tb)
74 if !y.Verify(RecordID(99401, "attempt-b")) {
75 t.Fatal("B lost its reboot evidence when A was proven")
76 }
77 if sig := tb.signalled(); len(sig) != 0 {
78 t.Fatalf("signalled %v", sig)
79 }
80}
81
82// parseRecord is proc.ParseRecord (tests).
83func parseRecord(id string) (int, string, bool) { return proc.ParseRecord(id) }
84