-
Notifications
You must be signed in to change notification settings - Fork 1
/
checker.go
55 lines (43 loc) · 1.22 KB
/
checker.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
package checker
import (
"errors"
"fmt"
"time"
"github.com/anishathalye/porcupine"
"github.com/resonatehq/durable-promise-test-harness/pkg/store"
"github.com/resonatehq/durable-promise-test-harness/pkg/utils"
)
// Checker validates that a history is correct with respect to some model.
type Checker struct {
*Visualizer
}
// Creates a new Checker with reasonable defaults.
func NewChecker() *Checker {
return &Checker{
Visualizer: NewVisualizer(),
}
}
// Check verifies the history is linearizably consistent with respect to the model.
func (c *Checker) Check(history []store.Operation) error {
model, events := newPorcupineModel(), makePorcupineEvents(history)
var pass bool
res, info := porcupine.CheckEventsVerbose(model, events, 1*time.Hour)
if res != porcupine.Illegal {
pass = true
}
today := time.Now().Format("01-02-2006_15-04-05")
filePath := fmt.Sprintf("test/results/%s/visualization.html", today)
err := utils.WriteStringToFile("", filePath)
if err != nil {
return err
}
err = porcupine.VisualizePath(model, info, filePath)
if err != nil {
return err
}
c.Summary(pass, today, history)
if !pass {
return errors.New("history is not linearizable, check results for more details")
}
return nil
}