-
Notifications
You must be signed in to change notification settings - Fork 0
/
s_keepalive_test.go
52 lines (45 loc) · 1004 Bytes
/
s_keepalive_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
package upax_go
// upax_go/s_keepalive_test.go
import (
"fmt"
xr "github.com/jddixon/rnglib_go"
. "gopkg.in/check.v1"
"time"
)
func (s *XLSuite) TestClusterKeepAlive(c *C) {
if VERBOSITY > 0 {
fmt.Println("TEST_CLUSTER_KEEP_ALIVE")
}
rng := xr.MakeSimpleRNG()
k := time.Duration(1 + rng.Intn(10))
interval := k * time.Millisecond
lifespan := 3 + rng.Intn(13)
msgCh := make(chan *UpaxClusterMsg, 2*lifespan)
stopCh := make(chan bool)
doneCh := make(chan bool)
var msgs []*UpaxClusterMsg
mgr, err := NewClusterKeepAliveMgr(
interval, lifespan, msgCh, stopCh, doneCh)
c.Assert(err, IsNil)
go mgr.Run()
done := false
select {
case <-time.After(time.Duration(2*lifespan) * interval):
c.Fatal("timed out waiting for done from ClusterKeepAliveMgr")
default:
for !done {
select {
case msg := <-msgCh:
msgs = append(msgs, msg)
case <-doneCh:
done = true
}
}
}
if done {
c.Assert(len(msgs), Equals, lifespan)
} else {
stopCh <- true
<-doneCh
}
}