Skip to content

Commit

Permalink
Added test to confirm that there is no deadlock when testQBFTBlock is…
Browse files Browse the repository at this point in the history
… set to 1 (#1272)

Co-authored-by: Ricardo Silva <[email protected]>
  • Loading branch information
jbhurat and ricardolyn authored Nov 2, 2021
1 parent de5e8b2 commit 919800f
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions consensus/istanbul/backend/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,38 @@ func TestGetProposer(t *testing.T) {
}
}

// TestQBFTTransitionDeadlock test whether a deadlock occurs when testQBFTBlock is set to 1
// This was fixed as part of commit 2a8310663ecafc0233758ca7883676bf568e926e
func TestQBFTTransitionDeadlock(t *testing.T) {
timeout := time.After(1 * time.Minute)
done := make(chan bool)
go func() {
chain, engine := newBlockChain(1, big.NewInt(1))
defer engine.Stop()
// Create an insert a new block into the chain.
block := makeBlock(chain, engine, chain.Genesis())
_, err := chain.InsertChain(types.Blocks{block})
if err != nil {
t.Errorf("Error inserting block: %v", err)
}

if err = engine.NewChainHead(); err != nil {
t.Errorf("Error posting NewChainHead Event: %v", err)
}

if !engine.IsQBFTConsensus() {
t.Errorf("IsQBFTConsensus() should return true after block insertion")
}
done <- true
}()

select {
case <-timeout:
t.Fatal("Deadlock occurred during IBFT to QBFT transition")
case <-done:
}
}

func TestIsQBFTConsensus(t *testing.T) {
chain, engine := newBlockChain(1, big.NewInt(2))
defer engine.Stop()
Expand Down

0 comments on commit 919800f

Please sign in to comment.