consensus: fix flaky TestPrepareProposalReceivesVoteExtensions

Signed-off-by: Thane Thomson <connect@thanethomson.com>
This commit is contained in:
Thane Thomson
2022-04-14 16:41:08 -04:00
parent c89890b111
commit cb970564d7
2 changed files with 14 additions and 15 deletions
+8 -9
View File
@@ -350,20 +350,19 @@ func validatePrecommit(
require.True(t, bytes.Equal(vote.BlockID.Hash, votedBlockHash), "Expected precommit to be for proposal block")
}
cs.mtx.RLock()
defer cs.mtx.RUnlock()
rs := cs.GetRoundState()
if lockedBlockHash == nil {
require.False(t, cs.LockedRound != lockRound || cs.LockedBlock != nil,
require.False(t, rs.LockedRound != lockRound || rs.LockedBlock != nil,
"Expected to be locked on nil at round %d. Got locked at round %d with block %v",
lockRound,
cs.LockedRound,
cs.LockedBlock)
rs.LockedRound,
rs.LockedBlock)
} else {
require.False(t, cs.LockedRound != lockRound || !bytes.Equal(cs.LockedBlock.Hash(), lockedBlockHash),
require.False(t, rs.LockedRound != lockRound || !bytes.Equal(rs.LockedBlock.Hash(), lockedBlockHash),
"Expected block to be locked on round %d, got %d. Got locked block %X, expected %X",
lockRound,
cs.LockedRound,
cs.LockedBlock.Hash(),
rs.LockedRound,
rs.LockedBlock.Hash(),
lockedBlockHash)
}
}
@@ -380,7 +379,7 @@ func subscribeToVoter(ctx context.Context, t *testing.T, cs *State, addr []byte,
vt[t] = struct{}{}
}
ch := make(chan tmpubsub.Message)
ch := make(chan tmpubsub.Message, 1)
if err := cs.eventBus.Observe(ctx, func(msg tmpubsub.Message) error {
vote := msg.Data().(types.EventDataVote)
// we only fire for our own votes
+6 -6
View File
@@ -2191,6 +2191,10 @@ func TestPrepareProposalReceivesVoteExtensions(t *testing.T) {
newRoundCh := subscribe(ctx, t, cs1.eventBus, types.EventQueryNewRound)
proposalCh := subscribe(ctx, t, cs1.eventBus, types.EventQueryCompleteProposal)
pv1, err := cs1.privValidator.GetPubKey(ctx)
require.NoError(t, err)
addr := pv1.Address()
voteCh := subscribeToVoter(ctx, t, cs1, addr)
startTestRound(ctx, cs1, height, round)
ensureNewRound(t, newRoundCh, height, round)
@@ -2208,14 +2212,10 @@ func TestPrepareProposalReceivesVoteExtensions(t *testing.T) {
signAddPrecommitWithExtension(ctx, t, cs1, config.ChainID(), blockID, voteExtensions[i+1], vs)
}
pv1, err := cs1.privValidator.GetPubKey(ctx)
require.NoError(t, err)
addr := pv1.Address()
voteCh := subscribeToVoter(ctx, t, cs1, addr, tmproto.PrecommitType)
ensurePrevote(t, voteCh, height, round)
// ensure that the height is committed.
ensurePrecommit(t, voteCh, height, round)
validatePrecommit(ctx, t, cs1, round, round, vss[0], blockID.Hash, blockID.Hash)
ensurePrecommitMatch(t, voteCh, height, round, blockID.Hash)
incrementHeight(vss[1:]...)
height++