Browse Source

consensus: fix startnextheightcorrectly test (#4938)

pull/4945/head
Callum Waters 5 years ago
committed by GitHub
parent
commit
e538ea03d1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 5 deletions
  1. +8
    -0
      consensus/common_test.go
  2. +12
    -5
      consensus/state_test.go

+ 8
- 0
consensus/common_test.go View File

@ -625,6 +625,14 @@ func ensureVote(voteCh <-chan tmpubsub.Message, height int64, round int,
} }
} }
func ensurePrecommitTimeout(ch <-chan tmpubsub.Message) {
select {
case <-time.After(ensureTimeout):
panic("Timeout expired while waiting for the Precommit to Timeout")
case <-ch:
}
}
func ensureNewEventOnChannel(ch <-chan tmpubsub.Message) { func ensureNewEventOnChannel(ch <-chan tmpubsub.Message) {
select { select {
case <-time.After(ensureTimeout): case <-time.After(ensureTimeout):


+ 12
- 5
consensus/state_test.go View File

@ -1458,7 +1458,10 @@ func (n *fakeTxNotifier) Notify() {
n.ch <- struct{}{} n.ch <- struct{}{}
} }
func TestStartNextHeightCorrectly(t *testing.T) {
// 2 vals precommit votes for a block but node times out waiting for the third. Move to next round
// and third precommit arrives which leads to the commit of that header and the correct
// start of the next round
func TestStartNextHeightCorrectlyAfterTimeout(t *testing.T) {
config.Consensus.SkipTimeoutCommit = false config.Consensus.SkipTimeoutCommit = false
cs1, vss := randState(4) cs1, vss := randState(4)
cs1.txNotifier = &fakeTxNotifier{ch: make(chan struct{})} cs1.txNotifier = &fakeTxNotifier{ch: make(chan struct{})}
@ -1468,6 +1471,7 @@ func TestStartNextHeightCorrectly(t *testing.T) {
proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal) proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
timeoutProposeCh := subscribe(cs1.eventBus, types.EventQueryTimeoutPropose) timeoutProposeCh := subscribe(cs1.eventBus, types.EventQueryTimeoutPropose)
precommitTimeoutCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound) newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
newBlockHeader := subscribe(cs1.eventBus, types.EventQueryNewBlockHeader) newBlockHeader := subscribe(cs1.eventBus, types.EventQueryNewBlockHeader)
@ -1497,11 +1501,14 @@ func TestStartNextHeightCorrectly(t *testing.T) {
// add precommits // add precommits
signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2) signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2)
signAddVotes(cs1, types.PrecommitType, theBlockHash, theBlockParts, vs3) signAddVotes(cs1, types.PrecommitType, theBlockHash, theBlockParts, vs3)
time.Sleep(5 * time.Millisecond)
signAddVotes(cs1, types.PrecommitType, theBlockHash, theBlockParts, vs4)
rs = cs1.GetRoundState()
assert.True(t, rs.TriggeredTimeoutPrecommit)
// wait till timeout occurs
ensurePrecommitTimeout(precommitTimeoutCh)
ensureNewRound(newRoundCh, height, round+1)
// majority is now reached
signAddVotes(cs1, types.PrecommitType, theBlockHash, theBlockParts, vs4)
ensureNewBlockHeader(newBlockHeader, height, theBlockHash) ensureNewBlockHeader(newBlockHeader, height, theBlockHash)


Loading…
Cancel
Save