Skip to content

Commit f88ddc6

Browse files
authored
Simplify Failover Test (#88)
* add wal logs and simplify test * hardcode test metadata input * remove wal error check * add lock to reading from wal
1 parent 8f68520 commit f88ddc6

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

epoch.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,9 @@ func (e *Epoch) createBlockVerificationTask(block Block, from NodeID, vote Vote)
12461246

12471247
record := BlockRecord(md, block.Bytes())
12481248
e.WAL.Append(record)
1249+
e.Logger.Debug("Persisted block to WAL",
1250+
zap.Uint64("round", md.Round),
1251+
zap.Stringer("digest", md.Digest))
12491252

12501253
if !e.storeProposal(block) {
12511254
e.Logger.Warn("Unable to store proposed block for the round", zap.Stringer("NodeID", from), zap.Uint64("round", md.Round))
@@ -1556,6 +1559,9 @@ func (e *Epoch) triggerProposalWaitTimeExpired(round uint64) {
15561559
e.Logger.Error("Failed appending empty vote", zap.Error(err))
15571560
return
15581561
}
1562+
e.Logger.Debug("Persisted empty vote to WAL",
1563+
zap.Uint64("round", round),
1564+
zap.Int("size", len(emptyVoteRecord)))
15591565

15601566
emptyVotes := e.getOrCreateEmptyVoteSetForRound(round)
15611567
emptyVotes.timedOut = true

epoch_failover_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,20 @@ func TestEpochLeaderFailover(t *testing.T) {
6161
// Then, don't do anything and wait for our node
6262
// to start complaining about a block not being notarized
6363

64-
for _, round := range []uint64{0, 1, 2} {
64+
for round := uint64(0); round < 3; round++ {
6565
notarizeAndFinalizeRound(t, nodes, round, round, e, bb, quorum, storage, false)
6666
}
6767

6868
bb.blockShouldBeBuilt <- struct{}{}
6969

7070
waitForEvent(t, start, e, timeoutDetected)
71-
71+
7272
lastBlock, _, ok := storage.Retrieve(storage.Height() - 1)
7373
require.True(t, ok)
7474

7575
prev := lastBlock.BlockHeader().Digest
7676

77-
md := ProtocolMetadata{
77+
emptyBlockMd := ProtocolMetadata{
7878
Round: 3,
7979
Seq: 2,
8080
Prev: prev,
@@ -83,8 +83,8 @@ func TestEpochLeaderFailover(t *testing.T) {
8383
nextBlockSeqToCommit := uint64(3)
8484
nextRoundToCommit := uint64(4)
8585

86-
emptyVoteFrom1 := createEmptyVote(md, nodes[1])
87-
emptyVoteFrom2 := createEmptyVote(md, nodes[2])
86+
emptyVoteFrom1 := createEmptyVote(emptyBlockMd, nodes[1])
87+
emptyVoteFrom2 := createEmptyVote(emptyBlockMd, nodes[2])
8888

8989
e.HandleMessage(&Message{
9090
EmptyVoteMessage: emptyVoteFrom1,
@@ -93,25 +93,25 @@ func TestEpochLeaderFailover(t *testing.T) {
9393
EmptyVoteMessage: emptyVoteFrom2,
9494
}, nodes[2])
9595

96-
// Ensure our node proposes block with sequence 3 for round 4
97-
notarizeAndFinalizeRound(t, nodes, nextRoundToCommit, nextBlockSeqToCommit, e, bb, quorum, storage, false)
98-
99-
// WAL must contain an empty vote and an empty block.
96+
wal.lock.Lock()
10097
walContent, err := wal.ReadAll()
10198
require.NoError(t, err)
102-
103-
// WAL should be: [..., <empty vote>, <empty block>, <notarization for 4>, <block3>]
104-
rawEmptyVote, rawEmptyNotarization := walContent[len(walContent)-4], walContent[len(walContent)-3]
105-
99+
wal.lock.Unlock()
100+
101+
rawEmptyVote, rawEmptyNotarization := walContent[len(walContent)-2], walContent[len(walContent)-1]
106102
emptyVote, err := ParseEmptyVoteRecord(rawEmptyVote)
107103
require.NoError(t, err)
108-
require.Equal(t, createEmptyVote(md, nodes[0]).Vote, emptyVote)
104+
require.Equal(t, createEmptyVote(emptyBlockMd, nodes[0]).Vote, emptyVote)
109105

110106
emptyNotarization, err := EmptyNotarizationFromRecord(rawEmptyNotarization, &testQCDeserializer{t: t})
111107
require.NoError(t, err)
112108
require.Equal(t, emptyVoteFrom1.Vote, emptyNotarization.Vote)
113109
require.Equal(t, uint64(3), emptyNotarization.Vote.Round)
114110
require.Equal(t, uint64(2), emptyNotarization.Vote.Seq)
111+
require.Equal(t, uint64(3), storage.Height())
112+
113+
// Ensure our node proposes block with sequence 3 for round 4
114+
notarizeAndFinalizeRound(t, nodes, nextRoundToCommit, nextBlockSeqToCommit, e, bb, quorum, storage, false)
115115
require.Equal(t, uint64(4), storage.Height())
116116
}
117117

0 commit comments

Comments
 (0)