-
Notifications
You must be signed in to change notification settings - Fork 4
/
benchmark_scenario_test.go
72 lines (58 loc) · 1.23 KB
/
benchmark_scenario_test.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
package isucandar
import (
"context"
"sync/atomic"
"testing"
)
type exampleScenario struct {
prepare uint32
load uint32
validation uint32
}
func (e *exampleScenario) Prepare(_ context.Context, _ *BenchmarkStep) error {
atomic.StoreUint32(&e.prepare, 1)
return nil
}
func (e *exampleScenario) Load(_ context.Context, _ *BenchmarkStep) error {
atomic.StoreUint32(&e.load, 1)
return nil
}
func (e *exampleScenario) Validation(_ context.Context, _ *BenchmarkStep) error {
atomic.StoreUint32(&e.validation, 1)
return nil
}
func TestBenchmarkAddScenario(t *testing.T) {
benchmark, err := NewBenchmark()
if err != nil {
t.Fatal(err)
}
e := &exampleScenario{
prepare: 0,
load: 0,
validation: 0,
}
benchmark.AddScenario(e)
result := benchmark.Start(context.Background())
if len(result.Errors.All()) > 0 {
t.Fatal(result.Errors.All())
}
if e.prepare != 1 || e.load != 1 || e.validation != 1 {
t.Fatal(e)
}
}
func TestBenchmarkAddScenarioPanic(t *testing.T) {
benchmark, err := NewBenchmark()
if err != nil {
t.Fatal(err)
}
var rerr interface{}
func() {
defer func() {
rerr = recover()
}()
benchmark.AddScenario(nil)
}()
if rerr == nil {
t.Fatal("Do not register invalid scenario")
}
}