forked from kandoo/beehive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
detached_test.go
61 lines (49 loc) · 958 Bytes
/
detached_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
package beehive
import (
"testing"
"time"
)
type testDetachedHandler struct {
ch chan bool
fork bool
}
type testDetachedMsg int
func (d *testDetachedHandler) Start(ctx RcvContext) {
if !d.fork {
d.ch <- true
return
}
b := ctx.StartDetached(&testDetachedHandler{
ch: d.ch,
fork: false,
})
msg := testDetachedMsg(0)
ctx.SendToBee(msg, b)
}
func (d *testDetachedHandler) Stop(ctx RcvContext) {
}
func (d *testDetachedHandler) Rcv(msg Msg, ctx RcvContext) error {
d.ch <- true
return nil
}
func TestDetached(t *testing.T) {
h := newHiveForTest()
app := h.NewApp("TestDetached")
nDetached := 10
msgCh := make(chan bool)
for i := 0; i < nDetached; i++ {
app.Detached(&testDetachedHandler{
ch: msgCh,
fork: true,
})
}
go h.Start()
for i := 0; i < nDetached*2; i++ {
select {
case <-msgCh:
case <-time.After(2 * time.Second):
t.Errorf("did not receive any message on the channel.")
}
}
h.Stop()
}