forked from danmux/floe
-
Notifications
You must be signed in to change notification settings - Fork 14
/
event_test.go
96 lines (81 loc) · 1.58 KB
/
event_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package event
import "testing"
type listener struct {
what func(e Event)
}
func (l *listener) Notify(e Event) {
l.what(e)
}
func TestQueue(t *testing.T) {
q := Queue{}
fired := false
done := make(chan bool)
l := &listener{
what: func(e Event) {
fired = true
if e.ID != 1 {
t.Error("event ID wrong", e.ID)
}
if e.RunRef.Run.String() != "h1-12" {
t.Error("bad hosted ref", e.RunRef.Run.String())
}
done <- true
},
}
q.Register(l)
e := Event{
RunRef: RunRef{
Run: HostedIDRef{
HostID: "h1",
ID: 12,
},
},
}
q.Publish(e)
<-done
if !fired {
t.Error("notify not fired")
}
}
func TestIsSystem(t *testing.T) {
fix := []struct{
tag string
is bool
}{
{"", false},
{"fo", false},
{"system.foo", false},
{"sys.bar", true},
}
for i, f := range fix {
e := Event{
Tag: f.tag,
}
if e.IsSystem() != f.is {
t.Errorf("%d - tag %s should have had IsSystem: %v", i, f.tag, f.is)
}
}
}
// The following benchmarks illustrate the relative performances of
// passing th reference by value or as a pointer.
// as of 2017/11 there is 1ns in it...
// BenchmarkRunRefPBR-8 500000000 3.15 ns/op
// BenchmarkRunRefPBV-8 300000000 4.32 ns/op
func BenchmarkRunRefPBP(b *testing.B) {
notnop := func (r *RunRef) {
r.ExecHost = "" // hopefully avoid any optimisers?
}
r := &RunRef{}
for i := 0; i < b.N; i++ {
notnop(r)
}
}
func BenchmarkRunRefPBV(b *testing.B) {
notnop := func (r RunRef) {
r.ExecHost = "" // hopefully avoid any optimisers?
}
r := RunRef{}
for i := 0; i < b.N; i++ {
notnop(r)
}
}