forked from lightstep/lightstep-tracer-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_handlers_test.go
53 lines (44 loc) · 1014 Bytes
/
event_handlers_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
package lightstep
import (
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
type handler1 struct {
foo int
}
func (h handler1) OnEvent(event Event) {
}
type handler2 struct {
bar string
}
func (h handler2) OnEvent(event Event) {}
var _ = Describe("SetGlobalEventHandler", func() {
var h1 handler1
var h2 handler2
BeforeEach(func() {
h1 = handler1{foo: 1}
h2 = handler2{bar: "bar"}
})
It("can be updated with different types of event handlers", func() {
Expect(func() { SetGlobalEventHandler(h1.OnEvent) }).NotTo(Panic())
Expect(func() { SetGlobalEventHandler(h2.OnEvent) }).NotTo(Panic())
})
It("does not race when setting and calling the handler", func() {
for i := 0; i < 100; i++ {
go func() {
SetGlobalEventHandler(h1.OnEvent)
}()
go func() {
emitEvent(newEventStartError(nil))
}()
go func() {
SetGlobalEventHandler(h2.OnEvent)
}()
go func() {
emitEvent(newEventStartError(nil))
}()
}
time.Sleep(time.Millisecond)
})
})