-
Notifications
You must be signed in to change notification settings - Fork 0
/
heartbeat_test.go
46 lines (40 loc) · 987 Bytes
/
heartbeat_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
package happy
import (
"testing"
"time"
"github.com/cnlisea/happy/pmgr"
"github.com/cnlisea/happy/proxy"
)
func Test_Happy_Heartbeat(t *testing.T) {
h := New(nil, 1, new(GameBase), nil)
h.Heartbeat(3 * time.Second)
h.Event(&Event{
Finish: func(h Happy, curRound, maxRound uint32, pMgr *pmgr.PMgr, disband bool, extend map[string]interface{}) {
t.Log("finish", time.Now().Unix())
},
})
h.Init()
t.Log("run", time.Now().Unix())
h.Run(false)
}
func Test_Happy_HeartbeatMsg(t *testing.T) {
h := New(nil, 1, new(GameBase), nil)
h.Heartbeat(3 * time.Second)
h.Event(&Event{
Finish: func(h Happy, curRound, maxRound uint32, pMgr *pmgr.PMgr, disband bool, extend map[string]interface{}) {
t.Log(time.Now().Unix())
},
})
h.Init()
t.Log(time.Now().Unix())
go func() {
for i := 0; i < 2; i++ {
time.Sleep(2900 * time.Millisecond)
h.Msg(&proxy.Msg{
Kind: proxy.MsgKindGame,
})
t.Log("send msg ts:", time.Now().Unix())
}
}()
h.Run(false)
}