Skip to content

Commit 430fbb5

Browse files
samliokyacovm
andauthored
add simple failover test (#276)
Co-authored-by: yacovm <[email protected]>
1 parent 68bae12 commit 430fbb5

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

epoch_failover_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,52 @@ func TestEpochLeaderFailoverWithEmptyNotarization(t *testing.T) {
9797
})
9898
}
9999

100+
func TestEpochRebroadcastsEmptyVoteAfterBlockProposalReceived(t *testing.T) {
101+
bb := &testutil.TestBlockBuilder{Out: make(chan *testutil.TestBlock, 1), BlockShouldBeBuilt: make(chan struct{}, 1)}
102+
nodes := []NodeID{{1}, {2}, {3}, {4}}
103+
104+
comm := newRebroadcastComm(nodes)
105+
conf, wal, _ := testutil.DefaultTestNodeEpochConfig(t, nodes[3], comm, bb)
106+
epochTime := conf.StartTime
107+
e, err := NewEpoch(conf)
108+
require.NoError(t, err)
109+
110+
require.NoError(t, e.Start())
111+
require.Equal(t, uint64(0), e.Metadata().Round)
112+
require.Equal(t, uint64(0), e.Metadata().Round)
113+
require.False(t, wal.ContainsEmptyVote(0))
114+
115+
bb.BlockShouldBeBuilt <- struct{}{}
116+
117+
// receive the block proposal for round 0
118+
md := e.Metadata()
119+
_, ok := bb.BuildBlock(context.Background(), md, emptyBlacklist)
120+
require.True(t, ok)
121+
block := <-bb.Out
122+
123+
vote, err := testutil.NewTestVote(block, nodes[0])
124+
require.NoError(t, err)
125+
err = e.HandleMessage(&Message{
126+
BlockMessage: &BlockMessage{
127+
Vote: *vote,
128+
Block: block,
129+
},
130+
}, nodes[0])
131+
require.NoError(t, err)
132+
133+
// ensure we have the block in our wal
134+
wal.AssertBlockProposal(0)
135+
wal.AssertWALSize(1)
136+
137+
// wait for the initial empty vote broadcast
138+
waitForEmptyVote(t, comm, e, 0, epochTime)
139+
require.Len(t, comm.emptyVotes, 0)
140+
141+
// advance another rebroadcast period and ensure more empty votes are sent
142+
waitForEmptyVote(t, comm, e, 0, epochTime)
143+
require.Len(t, comm.emptyVotes, 0)
144+
}
145+
100146
func TestEpochLeaderFailoverReceivesEmptyVotesEarly(t *testing.T) {
101147
bb := &testutil.TestBlockBuilder{Out: make(chan *testutil.TestBlock, 1), BlockShouldBeBuilt: make(chan struct{}, 1)}
102148
nodes := []NodeID{{1}, {2}, {3}, {4}}

0 commit comments

Comments
 (0)