File: surrogate_gossiper_test.go

package info (click to toggle)
golang-github-weaveworks-mesh 0.1%2Bgit20180323.0c91e69-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, trixie
  • size: 420 kB
  • sloc: sh: 60; makefile: 7
file content (57 lines) | stat: -rw-r--r-- 1,551 bytes parent folder | download
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(gossipInterval / 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(gossipInterval)
	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")
}