-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
92 lines (62 loc) · 1.62 KB
/
main_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
91
92
package main
import (
"gossip-gloomers/testutils"
"sort"
"testing"
"github.com/gkampitakis/go-snaps/snaps"
maelstrom "github.com/jepsen-io/maelstrom/demo/go"
"github.com/stretchr/testify/require"
)
func Test(t *testing.T) {
require := require.New(t)
node = maelstrom.NewNode()
link := testutils.NewLink(node)
client := testutils.NewClient("c0", link)
go main()
err := client.InitNode("n0", []string{"n0", "n1", "n2", "n3", "n4"})
require.NoError(err)
topologyOutput, err := client.RPC(TopologyRequest{
MessageBody: maelstrom.MessageBody{
Type: "topology",
MsgID: 2,
},
Topology: map[string][]string{
"n0": {"n3", "n1"},
"n1": {"n4", "n2", "n0"},
"n2": {"n1"},
"n3": {"n0", "n4"},
"n4": {"n1", "n3"},
},
})
require.NoError(err)
snaps.MatchSnapshot(t, topologyOutput)
broadcastOutput, err := client.RPC(BroadcastRequest{
MessageBody: maelstrom.MessageBody{
Type: "broadcast",
MsgID: 3,
},
Message: 1,
})
require.NoError(err)
snaps.MatchSnapshot(t, broadcastOutput)
gossipOutput1, err := link.Read()
require.NoError(err)
gossipOutput2, err := link.Read()
require.NoError(err)
gossipOutput3, err := link.Read()
require.NoError(err)
gossipOutput4, err := link.Read()
require.NoError(err)
gossipOutputs := []string{gossipOutput1, gossipOutput2, gossipOutput3, gossipOutput4}
// ensure consistency
sort.Strings(gossipOutputs)
for _, gossipOutput := range gossipOutputs {
snaps.MatchSnapshot(t, gossipOutput)
}
readOutput, err := client.RPC(maelstrom.MessageBody{
Type: "read",
MsgID: 4,
})
require.NoError(err)
snaps.MatchSnapshot(t, readOutput)
}