shikibu 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +82 -0
- data/lib/shikibu/activity.rb +84 -48
- data/lib/shikibu/actors.rb +129 -0
- data/lib/shikibu/app.rb +33 -19
- data/lib/shikibu/blobs.rb +42 -0
- data/lib/shikibu/channels.rb +240 -64
- data/lib/shikibu/constants.rb +8 -0
- data/lib/shikibu/context.rb +184 -14
- data/lib/shikibu/errors.rb +56 -0
- data/lib/shikibu/fs.rb +93 -0
- data/lib/shikibu/integrations/sidekiq.rb +9 -13
- data/lib/shikibu/middleware/rack_app.rb +17 -1
- data/lib/shikibu/replay.rb +242 -107
- data/lib/shikibu/storage/actor_ops.rb +331 -0
- data/lib/shikibu/storage/channel_ops.rb +421 -0
- data/lib/shikibu/storage/cursor_ops.rb +37 -0
- data/lib/shikibu/storage/sequel_storage.rb +400 -324
- data/lib/shikibu/storage/sqlite_ops.rb +58 -0
- data/lib/shikibu/supervisor.rb +279 -0
- data/lib/shikibu/tasks.rb +193 -0
- data/lib/shikibu/version.rb +1 -1
- data/lib/shikibu/worker.rb +155 -73
- data/lib/shikibu/workflow.rb +106 -48
- data/lib/shikibu.rb +4 -0
- data/schema/SEMANTICS.md +351 -0
- data/schema/db/migrations/mysql/20261123000000_outbox_claimed_at.sql +5 -0
- data/schema/db/migrations/mysql/20261201000000_actor_registry.sql +24 -0
- data/schema/db/migrations/mysql/20261202000000_actor_capabilities.sql +15 -0
- data/schema/db/migrations/mysql/20261203000000_payload_blobs.sql +11 -0
- data/schema/db/migrations/mysql/20261204000000_actor_fs.sql +13 -0
- data/schema/db/migrations/mysql/20261205000000_actor_tasks.sql +15 -0
- data/schema/db/migrations/mysql/20261206000000_actor_tasks_claimed_at.sql +7 -0
- data/schema/db/migrations/mysql/20261207000000_add_sandboxed.sql +5 -0
- data/schema/db/migrations/mysql/20261208000000_widen_actor_owner_columns.sql +15 -0
- data/schema/db/migrations/postgresql/20261123000000_outbox_claimed_at.sql +5 -0
- data/schema/db/migrations/postgresql/20261201000000_actor_registry.sql +23 -0
- data/schema/db/migrations/postgresql/20261202000000_actor_capabilities.sql +15 -0
- data/schema/db/migrations/postgresql/20261203000000_payload_blobs.sql +11 -0
- data/schema/db/migrations/postgresql/20261204000000_actor_fs.sql +13 -0
- data/schema/db/migrations/postgresql/20261205000000_actor_tasks.sql +15 -0
- data/schema/db/migrations/postgresql/20261206000000_actor_tasks_claimed_at.sql +7 -0
- data/schema/db/migrations/postgresql/20261207000000_add_sandboxed.sql +5 -0
- data/schema/db/migrations/postgresql/20261208000000_widen_actor_owner_columns.sql +7 -0
- data/schema/db/migrations/sqlite/20261123000000_outbox_claimed_at.sql +5 -0
- data/schema/db/migrations/sqlite/20261201000000_actor_registry.sql +23 -0
- data/schema/db/migrations/sqlite/20261202000000_actor_capabilities.sql +15 -0
- data/schema/db/migrations/sqlite/20261203000000_payload_blobs.sql +11 -0
- data/schema/db/migrations/sqlite/20261204000000_actor_fs.sql +13 -0
- data/schema/db/migrations/sqlite/20261205000000_actor_tasks.sql +15 -0
- data/schema/db/migrations/sqlite/20261206000000_actor_tasks_claimed_at.sql +7 -0
- data/schema/db/migrations/sqlite/20261207000000_add_sandboxed.sql +5 -0
- data/schema/db/migrations/sqlite/20261208000000_widen_actor_owner_columns.sql +7 -0
- data/schema/docs/column-values.md +10 -0
- data/schema/spec/ActorFS.tla +117 -0
- data/schema/spec/ActorFS_lww_monotonic.cfg +7 -0
- data/schema/spec/ActorFS_new.cfg +8 -0
- data/schema/spec/ActorFS_old.cfg +7 -0
- data/schema/spec/CompetingMessageClaim.tla +127 -0
- data/schema/spec/CompetingMessageClaimSplit.tla +132 -0
- data/schema/spec/CompetingMessageClaimSplit_atomic_lost.cfg +7 -0
- data/schema/spec/CompetingMessageClaimSplit_atomic_once.cfg +7 -0
- data/schema/spec/CompetingMessageClaimSplit_fixed.cfg +7 -0
- data/schema/spec/CompetingMessageClaimSplit_split_lost.cfg +7 -0
- data/schema/spec/CompetingMessageClaimSplit_split_once.cfg +7 -0
- data/schema/spec/CompetingMessageClaimSplit_waitonly_lost.cfg +7 -0
- data/schema/spec/CompetingMessageClaimSplit_waitonly_once.cfg +7 -0
- data/schema/spec/CompetingMessageClaim_new.cfg +10 -0
- data/schema/spec/CompetingMessageClaim_old.cfg +11 -0
- data/schema/spec/EpochFencing.tla +87 -0
- data/schema/spec/EpochFencingRuns.tla +107 -0
- data/schema/spec/EpochFencingRuns_epoch.cfg +6 -0
- data/schema/spec/EpochFencingRuns_none.cfg +6 -0
- data/schema/spec/EpochFencingRuns_witness.cfg +6 -0
- data/schema/spec/EpochFencingRuns_worker.cfg +6 -0
- data/schema/spec/EpochFencingRuns_worker1.cfg +6 -0
- data/schema/spec/EpochFencing_new.cfg +8 -0
- data/schema/spec/EpochFencing_old.cfg +9 -0
- data/schema/spec/InstanceClaim.tla +196 -0
- data/schema/spec/InstanceClaimVerdict.tla +116 -0
- data/schema/spec/InstanceClaimVerdict_changedrows.cfg +6 -0
- data/schema/spec/InstanceClaimVerdict_changedrows_live.cfg +6 -0
- data/schema/spec/InstanceClaimVerdict_foundrows.cfg +6 -0
- data/schema/spec/InstanceClaimVerdict_foundrows_live.cfg +6 -0
- data/schema/spec/InstanceClaim_atomic_unfenced.cfg +9 -0
- data/schema/spec/InstanceClaim_live.cfg +9 -0
- data/schema/spec/InstanceClaim_new.cfg +9 -0
- data/schema/spec/InstanceClaim_old.cfg +11 -0
- data/schema/spec/InstanceClaim_racy_fenced.cfg +9 -0
- data/schema/spec/README.md +97 -0
- data/schema/spec/SupervisorRestart.tla +108 -0
- data/schema/spec/SupervisorRestartCAS.tla +84 -0
- data/schema/spec/SupervisorRestartCAS_nonsticky.cfg +6 -0
- data/schema/spec/SupervisorRestartCAS_snapshot.cfg +6 -0
- data/schema/spec/SupervisorRestartCAS_sticky.cfg +6 -0
- data/schema/spec/SupervisorRestart_racy.cfg +7 -0
- data/schema/spec/SupervisorRestart_strict.cfg +7 -0
- data/schema/spec/TaskClaim.tla +92 -0
- data/schema/spec/TaskClaimReadBack.tla +84 -0
- data/schema/spec/TaskClaimReadBack_byid.cfg +6 -0
- data/schema/spec/TaskClaimReadBack_order.cfg +6 -0
- data/schema/spec/TaskClaim_new.cfg +8 -0
- data/schema/spec/TaskClaim_old.cfg +9 -0
- data/schema/spec/TaskReclaim.tla +110 -0
- data/schema/spec/TaskReclaimAttempts.tla +73 -0
- data/schema/spec/TaskReclaimAttempts_attempt.cfg +6 -0
- data/schema/spec/TaskReclaimAttempts_claimant.cfg +6 -0
- data/schema/spec/TaskReclaim_new.cfg +8 -0
- data/schema/spec/TaskReclaim_old.cfg +8 -0
- data/schema/spec/WaitRegistration.tla +170 -0
- data/schema/spec/WaitRegistrationSub.tla +133 -0
- data/schema/spec/WaitRegistrationSub_fixed.cfg +6 -0
- data/schema/spec/WaitRegistrationSub_fixed_guarded.cfg +6 -0
- data/schema/spec/WaitRegistrationSub_guardonly_reg.cfg +6 -0
- data/schema/spec/WaitRegistrationSub_guardonly_res.cfg +6 -0
- data/schema/spec/WaitRegistrationSub_head_reg.cfg +6 -0
- data/schema/spec/WaitRegistrationSub_head_res.cfg +6 -0
- data/schema/spec/WaitRegistrationSub_noclear_reg.cfg +6 -0
- data/schema/spec/WaitRegistrationSub_noclear_res.cfg +6 -0
- data/schema/spec/WaitRegistrationSub_unfencedreg_reg.cfg +6 -0
- data/schema/spec/WaitRegistrationSub_unfencedreg_res.cfg +6 -0
- data/schema/spec/WaitRegistration_new.cfg +10 -0
- data/schema/spec/WaitRegistration_old.cfg +11 -0
- data/schema/spec/WaitRegistration_residual.cfg +11 -0
- data/schema/spec/WaitRegistration_sweep.cfg +11 -0
- data/schema/spec/actorfs_check_test.go +165 -0
- data/schema/spec/claim_check_test.go +387 -0
- data/schema/spec/competing_claim_test.go +194 -0
- data/schema/spec/epoch_check_test.go +128 -0
- data/schema/spec/go.mod +3 -0
- data/schema/spec/supervisorrestart_check_test.go +131 -0
- data/schema/spec/taskclaim_check_test.go +135 -0
- data/schema/spec/taskreclaim_check_test.go +125 -0
- data/schema/spec/tlc-check.sh +45 -0
- data/schema/spec/tlc-matrix.txt +68 -0
- data/schema/spec/wait_check_test.go +256 -0
- metadata +121 -2
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
package spec
|
|
2
|
+
|
|
3
|
+
// Exhaustive BFS checker for SupervisorRestart.tla.
|
|
4
|
+
//
|
|
5
|
+
// Child A (permanent, fails -> group restart), child B (sibling).
|
|
6
|
+
// Expansion set snapshotted at decision time; cancel+respawn follows.
|
|
7
|
+
// Strict config: B cannot complete once restart begins (reliable cancel).
|
|
8
|
+
// Racy config: B may complete in the window (cooperative cancel).
|
|
9
|
+
//
|
|
10
|
+
// Verifies:
|
|
11
|
+
// - strict: CompletedNeverRespawned holds in every reachable state
|
|
12
|
+
// - racy: violation IS reachable (pins down the dependency on
|
|
13
|
+
// reliable cancellation)
|
|
14
|
+
|
|
15
|
+
import (
|
|
16
|
+
"fmt"
|
|
17
|
+
"testing"
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
type srState struct {
|
|
21
|
+
genA int
|
|
22
|
+
gsA string // running | failed
|
|
23
|
+
gsB string // running | completed | cancelled
|
|
24
|
+
inRestart bool
|
|
25
|
+
compB bool
|
|
26
|
+
respawnedB bool
|
|
27
|
+
phase string // stable | cancelling | spawning
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
func srKey(s srState) string {
|
|
31
|
+
return fmt.Sprintf("%d|%s|%s|%v|%v|%v|%s",
|
|
32
|
+
s.genA, s.gsA, s.gsB, s.inRestart, s.compB, s.respawnedB, s.phase)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
func srInit() srState {
|
|
36
|
+
return srState{genA: 1, gsA: "running", gsB: "running", phase: "stable"}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const srMaxGen = 3
|
|
40
|
+
|
|
41
|
+
func srNext(s srState, strict bool) []srState {
|
|
42
|
+
var out []srState
|
|
43
|
+
// FailA
|
|
44
|
+
if s.gsA == "running" && s.phase == "stable" {
|
|
45
|
+
n := s
|
|
46
|
+
n.gsA = "failed"
|
|
47
|
+
out = append(out, n)
|
|
48
|
+
}
|
|
49
|
+
// DecideRestart: snapshot expansion set
|
|
50
|
+
if s.phase == "stable" && s.gsA == "failed" && s.genA < srMaxGen {
|
|
51
|
+
n := s
|
|
52
|
+
n.inRestart = s.gsB != "completed"
|
|
53
|
+
n.phase = "cancelling"
|
|
54
|
+
out = append(out, n)
|
|
55
|
+
}
|
|
56
|
+
// CancelB
|
|
57
|
+
if s.phase == "cancelling" {
|
|
58
|
+
n := s
|
|
59
|
+
if n.gsB == "running" {
|
|
60
|
+
n.gsB = "cancelled"
|
|
61
|
+
}
|
|
62
|
+
n.phase = "spawning"
|
|
63
|
+
out = append(out, n)
|
|
64
|
+
}
|
|
65
|
+
// CompleteB: blocked mid-restart only in strict mode
|
|
66
|
+
if s.gsB == "running" && (!strict || s.phase == "stable") {
|
|
67
|
+
n := s
|
|
68
|
+
n.compB = true
|
|
69
|
+
n.gsB = "completed"
|
|
70
|
+
out = append(out, n)
|
|
71
|
+
}
|
|
72
|
+
// SpawnNewGens
|
|
73
|
+
if s.phase == "spawning" {
|
|
74
|
+
n := s
|
|
75
|
+
n.genA++
|
|
76
|
+
n.gsA = "running"
|
|
77
|
+
if s.inRestart {
|
|
78
|
+
n.gsB = "running"
|
|
79
|
+
}
|
|
80
|
+
n.respawnedB = s.respawnedB || (s.inRestart && s.compB)
|
|
81
|
+
n.inRestart = false
|
|
82
|
+
n.phase = "stable"
|
|
83
|
+
out = append(out, n)
|
|
84
|
+
}
|
|
85
|
+
return out
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
func srExplore(t *testing.T, strict bool) (states int, violationSeen, restartSeen bool) {
|
|
89
|
+
t.Helper()
|
|
90
|
+
seen := map[string]bool{}
|
|
91
|
+
queue := []srState{srInit()}
|
|
92
|
+
seen[srKey(queue[0])] = true
|
|
93
|
+
for len(queue) > 0 {
|
|
94
|
+
s := queue[0]
|
|
95
|
+
queue = queue[1:]
|
|
96
|
+
states++
|
|
97
|
+
if s.respawnedB {
|
|
98
|
+
violationSeen = true
|
|
99
|
+
}
|
|
100
|
+
if s.genA > 1 {
|
|
101
|
+
restartSeen = true
|
|
102
|
+
}
|
|
103
|
+
for _, n := range srNext(s, strict) {
|
|
104
|
+
k := srKey(n)
|
|
105
|
+
if !seen[k] {
|
|
106
|
+
seen[k] = true
|
|
107
|
+
queue = append(queue, n)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return states, violationSeen, restartSeen
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
func TestSupervisorRestart_Strict(t *testing.T) {
|
|
115
|
+
states, violated, restarted := srExplore(t, true)
|
|
116
|
+
t.Logf("strict: %d states, violated=%v restarted=%v", states, violated, restarted)
|
|
117
|
+
if violated {
|
|
118
|
+
t.Fatal("strict: completed child respawned despite reliable cancel")
|
|
119
|
+
}
|
|
120
|
+
if !restarted {
|
|
121
|
+
t.Fatal("strict: model never exercised a restart")
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
func TestSupervisorRestart_Racy(t *testing.T) {
|
|
126
|
+
states, violated, restarted := srExplore(t, false)
|
|
127
|
+
t.Logf("racy: %d states, violated=%v restarted=%v", states, violated, restarted)
|
|
128
|
+
if !violated {
|
|
129
|
+
t.Fatal("racy: expected CompletedNeverRespawned violation to be reachable")
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
package spec
|
|
2
|
+
|
|
3
|
+
// Exhaustive model checker for TaskClaim.tla (2 workers, 2 tasks).
|
|
4
|
+
// Establishes the same results TLC would report:
|
|
5
|
+
//
|
|
6
|
+
// java -jar tla2tools.jar -deadlock -config TaskClaim_new.cfg TaskClaim.tla
|
|
7
|
+
//
|
|
8
|
+
// new (CAS=TRUE): SingleClaimant holds over all reachable states.
|
|
9
|
+
// old (CAS=FALSE): a state where two workers both won the same task is
|
|
10
|
+
// reachable — the double-claim race the AND state='open' guard prevents.
|
|
11
|
+
|
|
12
|
+
import (
|
|
13
|
+
"fmt"
|
|
14
|
+
"testing"
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
const (
|
|
18
|
+
tcOpen = 0
|
|
19
|
+
tcClaimed = 1
|
|
20
|
+
tcDone = 2
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
type tcState struct {
|
|
24
|
+
state [2]int // per task: open/claimed/done
|
|
25
|
+
claimedBy [2]string // per task: "", w1, w2
|
|
26
|
+
picked [2]string // per worker: candidate task "", t0, t1
|
|
27
|
+
won [2]uint // per worker: bitmask of tasks its claim won
|
|
28
|
+
violated bool
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
func (s tcState) key() string {
|
|
32
|
+
return fmt.Sprintf("%d,%d|%s,%s|%s,%s|%d,%d|%v",
|
|
33
|
+
s.state[0], s.state[1], s.claimedBy[0], s.claimedBy[1],
|
|
34
|
+
s.picked[0], s.picked[1], s.won[0], s.won[1], s.violated)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var tcWorkers = [2]string{"w1", "w2"}
|
|
38
|
+
var tcTasks = [2]string{"t0", "t1"}
|
|
39
|
+
|
|
40
|
+
func tcSuccessors(s tcState, cas bool) []tcState {
|
|
41
|
+
var out []tcState
|
|
42
|
+
add := func(n tcState) { out = append(out, n) }
|
|
43
|
+
for i, w := range tcWorkers {
|
|
44
|
+
// Pick: observe an open task as candidate.
|
|
45
|
+
if s.picked[i] == "" {
|
|
46
|
+
for ti := range tcTasks {
|
|
47
|
+
if s.state[ti] == tcOpen {
|
|
48
|
+
n := s
|
|
49
|
+
n.picked[i] = tcTasks[ti]
|
|
50
|
+
add(n)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Claim: guarded (task still open) or racy write.
|
|
55
|
+
if s.picked[i] != "" {
|
|
56
|
+
var ti int
|
|
57
|
+
for j, t := range tcTasks {
|
|
58
|
+
if s.picked[i] == t {
|
|
59
|
+
ti = j
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
success := !cas || s.state[ti] == tcOpen
|
|
63
|
+
if success {
|
|
64
|
+
n := s
|
|
65
|
+
n.state[ti] = tcClaimed
|
|
66
|
+
n.claimedBy[ti] = w
|
|
67
|
+
n.won[i] |= 1 << ti
|
|
68
|
+
for j := range tcWorkers {
|
|
69
|
+
if j != i && n.won[j]&(1<<ti) != 0 {
|
|
70
|
+
n.violated = true
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
n.picked[i] = ""
|
|
74
|
+
add(n)
|
|
75
|
+
} else {
|
|
76
|
+
n := s
|
|
77
|
+
n.picked[i] = ""
|
|
78
|
+
add(n)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Complete: claimant finishes its task.
|
|
82
|
+
for ti := range tcTasks {
|
|
83
|
+
if s.state[ti] == tcClaimed && s.claimedBy[ti] == w {
|
|
84
|
+
n := s
|
|
85
|
+
n.state[ti] = tcDone
|
|
86
|
+
add(n)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return out
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
func tcCheck(t *testing.T, cas bool) (states int, violationAt int) {
|
|
94
|
+
t.Helper()
|
|
95
|
+
start := tcState{}
|
|
96
|
+
seen := map[string]bool{start.key(): true}
|
|
97
|
+
queue := []tcState{start}
|
|
98
|
+
for len(queue) > 0 {
|
|
99
|
+
s := queue[0]
|
|
100
|
+
queue = queue[1:]
|
|
101
|
+
states++
|
|
102
|
+
if s.violated && violationAt == 0 {
|
|
103
|
+
violationAt = states
|
|
104
|
+
}
|
|
105
|
+
// claimant sanity: claimed => claimedBy is a real worker
|
|
106
|
+
for ti := range tcTasks {
|
|
107
|
+
if s.state[ti] == tcClaimed && s.claimedBy[ti] == "" {
|
|
108
|
+
t.Fatalf("task claimed by nobody: %+v", s)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
for _, n := range tcSuccessors(s, cas) {
|
|
112
|
+
if !seen[n.key()] {
|
|
113
|
+
seen[n.key()] = true
|
|
114
|
+
queue = append(queue, n)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return states, violationAt
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
func TestTaskClaim_CAS_SingleClaimant(t *testing.T) {
|
|
122
|
+
states, violationAt := tcCheck(t, true)
|
|
123
|
+
if violationAt != 0 {
|
|
124
|
+
t.Fatalf("SingleClaimant violated at state %d", violationAt)
|
|
125
|
+
}
|
|
126
|
+
t.Logf("CAS: %d states, SingleClaimant held", states)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
func TestTaskClaim_NoCAS_DoubleClaimReachable(t *testing.T) {
|
|
130
|
+
states, violationAt := tcCheck(t, false)
|
|
131
|
+
if violationAt == 0 {
|
|
132
|
+
t.Fatalf("expected double-claim state unreachable?? %d states", states)
|
|
133
|
+
}
|
|
134
|
+
t.Logf("no CAS: %d states, violation first reachable at %d", states, violationAt)
|
|
135
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
package spec
|
|
2
|
+
|
|
3
|
+
// Exhaustive BFS checker for TaskReclaim.tla.
|
|
4
|
+
//
|
|
5
|
+
// One task, two workers. Claim (CAS) -> unconditional side effect ->
|
|
6
|
+
// completion write. Reclaim may fire on any claimed task (no heartbeat:
|
|
7
|
+
// staleness is heuristic and may hit slow-but-alive workers).
|
|
8
|
+
//
|
|
9
|
+
// Verifies:
|
|
10
|
+
// - fenced config: NoClobber holds in every reachable state
|
|
11
|
+
// - unfenced config: a clobbering write IS reachable (fencing is load-bearing)
|
|
12
|
+
// - both configs: duplicate side-effect execution is reachable
|
|
13
|
+
// (at-least-once semantics — fencing protects the row, not the work)
|
|
14
|
+
|
|
15
|
+
import (
|
|
16
|
+
"fmt"
|
|
17
|
+
"testing"
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
type trState struct {
|
|
21
|
+
state string // "open" | "claimed" | "done"
|
|
22
|
+
claimedBy int // -1 none, 0/1 worker
|
|
23
|
+
phase [2]int // 0 idle, 1 busy, 2 execed
|
|
24
|
+
execs [2]int
|
|
25
|
+
writer int // -1 none
|
|
26
|
+
clobbered bool
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
func trKey(s trState) string {
|
|
30
|
+
return fmt.Sprintf("%s|%d|%d%d|%d%d|%d|%v",
|
|
31
|
+
s.state, s.claimedBy, s.phase[0], s.phase[1], s.execs[0], s.execs[1], s.writer, s.clobbered)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
func trInit() trState {
|
|
35
|
+
return trState{state: "open", claimedBy: -1, writer: -1}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
func trNext(s trState, fenced bool) []trState {
|
|
39
|
+
var out []trState
|
|
40
|
+
for w := 0; w < 2; w++ {
|
|
41
|
+
// Claim (CAS: only when open)
|
|
42
|
+
if s.phase[w] == 0 && s.state == "open" {
|
|
43
|
+
n := s
|
|
44
|
+
n.state = "claimed"
|
|
45
|
+
n.claimedBy = w
|
|
46
|
+
n.phase[w] = 1
|
|
47
|
+
out = append(out, n)
|
|
48
|
+
}
|
|
49
|
+
// Side effect: unconditional once claim held
|
|
50
|
+
if s.phase[w] == 1 && s.execs[w] < 2 { // same per-worker cap as TaskReclaim.tla
|
|
51
|
+
n := s
|
|
52
|
+
n.execs[w]++
|
|
53
|
+
n.phase[w] = 2
|
|
54
|
+
out = append(out, n)
|
|
55
|
+
}
|
|
56
|
+
// Completion write
|
|
57
|
+
if s.phase[w] == 2 {
|
|
58
|
+
n := s
|
|
59
|
+
guarded := s.state == "claimed" && s.claimedBy == w
|
|
60
|
+
lands := guarded || !fenced
|
|
61
|
+
if lands {
|
|
62
|
+
if s.state == "done" {
|
|
63
|
+
n.clobbered = true
|
|
64
|
+
}
|
|
65
|
+
n.state = "done"
|
|
66
|
+
n.writer = w
|
|
67
|
+
}
|
|
68
|
+
n.phase[w] = 0
|
|
69
|
+
out = append(out, n)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Reclaim: any claimed task may return to open
|
|
73
|
+
if s.state == "claimed" {
|
|
74
|
+
n := s
|
|
75
|
+
n.state = "open"
|
|
76
|
+
n.claimedBy = -1
|
|
77
|
+
out = append(out, n)
|
|
78
|
+
}
|
|
79
|
+
return out
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
func trExplore(t *testing.T, fenced bool) (states int, clobberedSeen, dupExecSeen bool) {
|
|
83
|
+
t.Helper()
|
|
84
|
+
seen := map[string]bool{}
|
|
85
|
+
queue := []trState{trInit()}
|
|
86
|
+
seen[trKey(queue[0])] = true
|
|
87
|
+
for len(queue) > 0 {
|
|
88
|
+
s := queue[0]
|
|
89
|
+
queue = queue[1:]
|
|
90
|
+
states++
|
|
91
|
+
if s.clobbered {
|
|
92
|
+
clobberedSeen = true
|
|
93
|
+
}
|
|
94
|
+
if s.execs[0]+s.execs[1] >= 2 {
|
|
95
|
+
dupExecSeen = true
|
|
96
|
+
}
|
|
97
|
+
for _, n := range trNext(s, fenced) {
|
|
98
|
+
k := trKey(n)
|
|
99
|
+
if !seen[k] {
|
|
100
|
+
seen[k] = true
|
|
101
|
+
queue = append(queue, n)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return states, clobberedSeen, dupExecSeen
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
func TestTaskReclaim_Fenced(t *testing.T) {
|
|
109
|
+
states, clobbered, dup := trExplore(t, true)
|
|
110
|
+
t.Logf("fenced: %d states, clobbered=%v dupExec=%v", states, clobbered, dup)
|
|
111
|
+
if clobbered {
|
|
112
|
+
t.Fatal("fenced: clobbering write reachable — fencing broken")
|
|
113
|
+
}
|
|
114
|
+
if !dup {
|
|
115
|
+
t.Fatal("fenced: duplicate execution SHOULD be reachable (at-least-once)")
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
func TestTaskReclaim_Unfenced(t *testing.T) {
|
|
120
|
+
states, clobbered, _ := trExplore(t, false)
|
|
121
|
+
t.Logf("unfenced: %d states, clobbered=%v", states, clobbered)
|
|
122
|
+
if !clobbered {
|
|
123
|
+
t.Fatal("unfenced: expected clobbering write to be reachable")
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Model-check every config in tlc-matrix.txt with TLC and compare the
|
|
3
|
+
# verdict with the expected one. The verdict comes from TLC's exit code:
|
|
4
|
+
# 0 = no error, 12 = invariant violated, 13 = property violated (an action
|
|
5
|
+
# property such as [][x' >= x]_x counts as safety, anything else under
|
|
6
|
+
# PROPERTIES as liveness). Any other exit code -- parse error, "successor
|
|
7
|
+
# state is not completely specified", missing cfg, crash -- fails the run.
|
|
8
|
+
#
|
|
9
|
+
# usage: spec/tlc-check.sh /path/to/tla2tools.jar
|
|
10
|
+
set -u
|
|
11
|
+
cd "$(dirname "$0")"
|
|
12
|
+
jar=${1:?usage: tlc-check.sh /path/to/tla2tools.jar}
|
|
13
|
+
meta=$(mktemp -d)
|
|
14
|
+
trap 'rm -rf "${meta:?}"' EXIT
|
|
15
|
+
fail=0
|
|
16
|
+
while read -r cfg module expect prop; do
|
|
17
|
+
case "$cfg" in '' | '#'*) continue ;; esac
|
|
18
|
+
out=$(java -XX:+UseParallelGC -cp "$jar" tlc2.TLC -workers 1 -deadlock \
|
|
19
|
+
-metadir "$meta/$cfg" -config "$cfg.cfg" "$module.tla" 2>&1)
|
|
20
|
+
code=$?
|
|
21
|
+
case $code in
|
|
22
|
+
0) got=pass ;;
|
|
23
|
+
12) got=safety ;;
|
|
24
|
+
13) if grep -Eq "Action property [A-Za-z0-9_]+ is violated" <<<"$out"; then
|
|
25
|
+
got=safety
|
|
26
|
+
else
|
|
27
|
+
got=liveness
|
|
28
|
+
fi ;;
|
|
29
|
+
*) got="error(exit $code)" ;;
|
|
30
|
+
esac
|
|
31
|
+
if [ "$got" = safety ] && [ -n "${prop:-}" ] &&
|
|
32
|
+
! grep -Eq "(Invariant|Action property) $prop is violated" <<<"$out"; then
|
|
33
|
+
got="safety (not $prop)"
|
|
34
|
+
fi
|
|
35
|
+
if [ "$got" = "$expect" ]; then
|
|
36
|
+
echo "ok $cfg: $got${prop:+ $prop}"
|
|
37
|
+
else
|
|
38
|
+
echo "FAIL $cfg: expected $expect${prop:+ $prop}, got $got"
|
|
39
|
+
tail -n 25 <<<"$out"
|
|
40
|
+
fail=1
|
|
41
|
+
fi
|
|
42
|
+
done <tlc-matrix.txt
|
|
43
|
+
# Newer TLC builds drop trace-exploration specs next to the model.
|
|
44
|
+
rm -f ./*_TTrace_*.tla ./*_TTrace_*.bin
|
|
45
|
+
exit $fail
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# TLC verdict for every config in this directory.
|
|
2
|
+
# <cfg> <module> <expect> [<property>]
|
|
3
|
+
# expect: pass | safety (invariant or action property) | liveness (temporal)
|
|
4
|
+
# For safety, <property> must be the one TLC reports as violated.
|
|
5
|
+
# tlc-check.sh fails on any other outcome, including TLC errors.
|
|
6
|
+
|
|
7
|
+
InstanceClaim_old InstanceClaim safety NoStaleWrite
|
|
8
|
+
InstanceClaim_new InstanceClaim pass
|
|
9
|
+
InstanceClaim_live InstanceClaim pass
|
|
10
|
+
InstanceClaim_atomic_unfenced InstanceClaim safety NoStaleWrite
|
|
11
|
+
InstanceClaim_racy_fenced InstanceClaim safety LegitimateWriters
|
|
12
|
+
InstanceClaimVerdict_foundrows InstanceClaimVerdict pass
|
|
13
|
+
InstanceClaimVerdict_changedrows InstanceClaimVerdict safety NoFalseLoss
|
|
14
|
+
InstanceClaimVerdict_foundrows_live InstanceClaimVerdict pass
|
|
15
|
+
InstanceClaimVerdict_changedrows_live InstanceClaimVerdict liveness
|
|
16
|
+
|
|
17
|
+
EpochFencing_old EpochFencing safety NoStaleWrite
|
|
18
|
+
EpochFencing_new EpochFencing pass
|
|
19
|
+
EpochFencingRuns_none EpochFencingRuns safety NoStaleWrite
|
|
20
|
+
EpochFencingRuns_worker EpochFencingRuns safety NoStaleWrite
|
|
21
|
+
EpochFencingRuns_worker1 EpochFencingRuns safety NoStaleWrite
|
|
22
|
+
EpochFencingRuns_epoch EpochFencingRuns pass
|
|
23
|
+
EpochFencingRuns_witness EpochFencingRuns safety NoTwoRunsSameWorker
|
|
24
|
+
|
|
25
|
+
CompetingMessageClaim_old CompetingMessageClaim liveness
|
|
26
|
+
CompetingMessageClaim_new CompetingMessageClaim pass
|
|
27
|
+
CompetingMessageClaimSplit_split_once CompetingMessageClaimSplit safety AtMostOneConsume
|
|
28
|
+
CompetingMessageClaimSplit_split_lost CompetingMessageClaimSplit safety NoLostMessage
|
|
29
|
+
CompetingMessageClaimSplit_waitonly_once CompetingMessageClaimSplit safety AtMostOneConsume
|
|
30
|
+
CompetingMessageClaimSplit_waitonly_lost CompetingMessageClaimSplit pass
|
|
31
|
+
CompetingMessageClaimSplit_atomic_once CompetingMessageClaimSplit pass
|
|
32
|
+
CompetingMessageClaimSplit_atomic_lost CompetingMessageClaimSplit safety NoLostMessage
|
|
33
|
+
CompetingMessageClaimSplit_fixed CompetingMessageClaimSplit pass
|
|
34
|
+
|
|
35
|
+
WaitRegistration_old WaitRegistration safety NoMissedWakeup
|
|
36
|
+
WaitRegistration_new WaitRegistration pass
|
|
37
|
+
WaitRegistration_residual WaitRegistration safety NoMissedWakeup
|
|
38
|
+
WaitRegistration_sweep WaitRegistration pass
|
|
39
|
+
WaitRegistrationSub_head_reg WaitRegistrationSub safety RegConsistent
|
|
40
|
+
WaitRegistrationSub_head_res WaitRegistrationSub safety NoResurrection
|
|
41
|
+
WaitRegistrationSub_unfencedreg_reg WaitRegistrationSub safety RegConsistent
|
|
42
|
+
WaitRegistrationSub_unfencedreg_res WaitRegistrationSub safety NoResurrection
|
|
43
|
+
WaitRegistrationSub_noclear_reg WaitRegistrationSub safety RegConsistent
|
|
44
|
+
WaitRegistrationSub_noclear_res WaitRegistrationSub safety NoResurrection
|
|
45
|
+
WaitRegistrationSub_guardonly_reg WaitRegistrationSub safety RegConsistent
|
|
46
|
+
WaitRegistrationSub_guardonly_res WaitRegistrationSub pass
|
|
47
|
+
WaitRegistrationSub_fixed WaitRegistrationSub pass
|
|
48
|
+
WaitRegistrationSub_fixed_guarded WaitRegistrationSub pass
|
|
49
|
+
|
|
50
|
+
TaskClaim_old TaskClaim safety SingleClaimant
|
|
51
|
+
TaskClaim_new TaskClaim pass
|
|
52
|
+
TaskClaimReadBack_order TaskClaimReadBack safety ReadBackIsOwnClaim
|
|
53
|
+
TaskClaimReadBack_byid TaskClaimReadBack pass
|
|
54
|
+
|
|
55
|
+
TaskReclaim_old TaskReclaim safety NoClobber
|
|
56
|
+
TaskReclaim_new TaskReclaim pass
|
|
57
|
+
TaskReclaimAttempts_claimant TaskReclaimAttempts safety NoStaleAttemptLands
|
|
58
|
+
TaskReclaimAttempts_attempt TaskReclaimAttempts pass
|
|
59
|
+
|
|
60
|
+
SupervisorRestart_strict SupervisorRestart pass
|
|
61
|
+
SupervisorRestart_racy SupervisorRestart safety CompletedNeverRespawned
|
|
62
|
+
SupervisorRestartCAS_sticky SupervisorRestartCAS pass
|
|
63
|
+
SupervisorRestartCAS_nonsticky SupervisorRestartCAS safety CompletedNeverRespawned
|
|
64
|
+
SupervisorRestartCAS_snapshot SupervisorRestartCAS safety CompletedNeverRespawned
|
|
65
|
+
|
|
66
|
+
ActorFS_old ActorFS safety NoLostUpdate
|
|
67
|
+
ActorFS_new ActorFS pass
|
|
68
|
+
ActorFS_lww_monotonic ActorFS safety VersionNeverRegresses
|