-
Notifications
You must be signed in to change notification settings - Fork 0
/
checking.go
94 lines (91 loc) · 2.02 KB
/
checking.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package timeout
import (
"fmt"
"time"
"github.com/netrixframework/netrix/log"
"github.com/netrixframework/netrix/strategies"
"github.com/netrixframework/netrix/util/z3"
)
func (t *TimeoutStrategy) findRandomPendingEvent(ctx *strategies.Context) (*pendingEvent, bool) {
if !t.config.SpuriousCheck {
return t.pendingEvents.RandomValue()
}
if t.pendingEvents.Size() < t.config.PendingEventThreshold {
return nil, false
}
messages := 0
timeouts := 0
solver := t.z3solver
solver.Push()
for _, p := range t.pendingEvents.IterValues() {
if p.timeout != nil {
timeouts = timeouts + 1
} else {
messages = messages + 1
}
for _, c := range p.constraints {
solver.Assert(c)
}
latest, ok := ctx.EventDAG.GetLatestNode(p.replica)
if !ok {
continue
}
latestSymbol, ok := t.symbolMap.Get(fmt.Sprintf("e_%d", latest.ID))
if !ok {
continue
}
pSymbol, ok := t.symbolMap.Get(p.label)
if !ok {
continue
}
solver.Assert(latestSymbol.Sub(pSymbol).Le(t.z3context.Int(0)))
}
start := time.Now()
var randomEvent *pendingEvent = nil
for _, e := range t.pendingEvents.IterValues() {
t.Logger.With(log.LogParams{
"event": e.label,
"replica": e.replica,
}).Debug("Checking if event is minimal")
solver.Push()
eSymbol, ok := t.symbolMap.Get(e.label)
if !ok {
continue
}
for _, p := range t.pendingEvents.IterValues() {
if p.label != e.label {
pSymbol, ok := t.symbolMap.Get(p.label)
if ok {
solver.Assert(eSymbol.Le(pSymbol))
}
}
}
sOk := solver.Check()
solver.Pop()
if sOk == z3.True && e.fire() {
t.Logger.With(log.LogParams{
"event": e.label,
"replica": e.replica,
}).Debug("Found event")
randomEvent = e
break
}
}
solver.Pop()
duration := time.Since(start)
if randomEvent != nil {
ch := choice{
timeouts: timeouts,
messages: messages,
time: duration,
}
if randomEvent.timeout != nil {
ch.choice = 1
} else {
ch.choice = 0
}
t.records.updateChoice(ctx, ch)
return randomEvent, true
}
return nil, false
}