forked from weaveworks/mesh
-
Notifications
You must be signed in to change notification settings - Fork 1
/
surrogate_gossiper_test.go
57 lines (49 loc) · 1.54 KB
/
surrogate_gossiper_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
package mesh
import "testing"
import "time"
import "github.com/stretchr/testify/require"
func TestSurrogateGossiperUnicast(t *testing.T) {
t.Skip("TODO")
}
func TestSurrogateGossiperBroadcast(t *testing.T) {
t.Skip("TODO")
}
func TestSurrogateGossiperGossip(t *testing.T) {
t.Skip("TODO")
}
func checkOnGossip(t *testing.T, s Gossiper, input, expected []byte) {
r, err := s.OnGossip(input)
require.NoError(t, err)
if r == nil {
if expected == nil {
return
}
require.Fail(t, "Gossip result should NOT be nil, but was")
}
require.Equal(t, [][]byte{expected}, r.Encode())
}
func TestSurrogateGossiperOnGossip(t *testing.T) {
myTime := time.Now()
now = func() time.Time { return myTime }
s := &surrogateGossiper{}
msg := [][]byte{[]byte("test 1"), []byte("test 2"), []byte("test 3"), []byte("test 4")}
checkOnGossip(t, s, msg[0], msg[0])
checkOnGossip(t, s, msg[1], msg[1])
checkOnGossip(t, s, msg[0], nil)
checkOnGossip(t, s, msg[1], nil)
myTime = myTime.Add(defaultGossipInterval / 2) // Should not trigger cleardown
checkOnGossip(t, s, msg[2], msg[2]) // Only clears out old ones on new entry
checkOnGossip(t, s, msg[0], nil)
checkOnGossip(t, s, msg[1], nil)
myTime = myTime.Add(defaultGossipInterval)
checkOnGossip(t, s, msg[0], nil)
checkOnGossip(t, s, msg[3], msg[3]) // Only clears out old ones on new entry
checkOnGossip(t, s, msg[0], msg[0])
checkOnGossip(t, s, msg[0], nil)
}
func TestSurrogateGossipDataEncode(t *testing.T) {
t.Skip("TODO")
}
func TestSurrogateGossipDataMerge(t *testing.T) {
t.Skip("TODO")
}