forked from hashicorp/memberlist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
integ_test.go
90 lines (77 loc) · 1.93 KB
/
integ_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
package memberlist
import (
"fmt"
"os"
"testing"
"time"
)
// CheckInteg will skip a test if integration testing is not enabled.
func CheckInteg(t *testing.T) {
if !IsInteg() {
t.SkipNow()
}
}
// IsInteg returns a boolean telling you if we're in integ testing mode.
func IsInteg() bool {
return os.Getenv("INTEG_TESTS") != ""
}
// Tests the memberlist by creating a cluster of 100 nodes
// and checking that we get strong convergence of changes.
func TestMemberlist_Integ(t *testing.T) {
CheckInteg(t)
num := 16
var members []*Memberlist
secret := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
eventCh := make(chan NodeEvent, num)
addr := "127.0.0.1"
for i := 0; i < num; i++ {
c := DefaultLANConfig()
c.Name = fmt.Sprintf("%s:%d", addr, 12345+i)
c.BindAddr = addr
c.BindPort = 12345 + i
c.ProbeInterval = 20 * time.Millisecond
c.ProbeTimeout = 100 * time.Millisecond
c.GossipInterval = 20 * time.Millisecond
c.PushPullInterval = 200 * time.Millisecond
c.SecretKey = secret
c.Logger = testLoggerWithName(t, c.Name)
if i == 0 {
c.Events = &ChannelEventDelegate{eventCh}
}
m, err := Create(c)
if err != nil {
t.Fatalf("unexpected err: %s", err)
}
defer m.Shutdown()
members = append(members, m)
if i > 0 {
last := members[i-1]
num, err := m.Join([]string{last.config.Name})
if num == 0 || err != nil {
t.Fatalf("unexpected err: %s", err)
}
}
}
// Wait and print debug info
breakTimer := time.After(250 * time.Millisecond)
WAIT:
for {
select {
case e := <-eventCh:
if e.Event == NodeJoin {
t.Logf("[DEBUG] Node join: %v (%d)", *e.Node, members[0].NumMembers())
} else {
t.Logf("[DEBUG] Node leave: %v (%d)", *e.Node, members[0].NumMembers())
}
case <-breakTimer:
break WAIT
}
}
for idx, m := range members {
got := m.NumMembers()
if got != num {
t.Errorf("bad num members at idx %d. Expected %d. Got %d.",
idx, num, got)
}
}
}