From 15eed81f12be1dcc3e7e2ba74097752ff40692c4 Mon Sep 17 00:00:00 2001 From: Erik Grinaker Date: Tue, 5 Jan 2021 11:44:03 +0100 Subject: [PATCH] test/consensus: improve WaitGroup handling in Byzantine tests (#5861) Fixes #5845. --- consensus/byzantine_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/consensus/byzantine_test.go b/consensus/byzantine_test.go index 4e31df98d..a82242db2 100644 --- a/consensus/byzantine_test.go +++ b/consensus/byzantine_test.go @@ -166,14 +166,14 @@ func TestByzantinePrevoteEquivocation(t *testing.T) { evidenceFromEachValidator := make([]types.Evidence, nValidators) wg := new(sync.WaitGroup) - wg.Add(4) for i := 0; i < nValidators; i++ { + wg.Add(1) go func(i int) { + defer wg.Done() for msg := range blocksSubs[i].Out() { block := msg.Data().(types.EventDataNewBlock).Block if len(block.Evidence.Evidence) != 0 { evidenceFromEachValidator[i] = block.Evidence.Evidence[0] - wg.Done() return } } @@ -340,8 +340,8 @@ func TestByzantineConflictingProposalsWithPartition(t *testing.T) { // wait till everyone makes the first new block // (one of them already has) wg := new(sync.WaitGroup) - wg.Add(2) for i := 1; i < N-1; i++ { + wg.Add(1) go func(j int) { <-blocksSubs[j].Out() wg.Done()