Browse Source

test/consensus: improve WaitGroup handling in Byzantine tests (#5861)

Fixes #5845.
pull/5863/head
Erik Grinaker 4 years ago
committed by GitHub
parent
commit
85353d9af5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions
  1. +3
    -3
      consensus/byzantine_test.go

+ 3
- 3
consensus/byzantine_test.go View File

@ -166,14 +166,14 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
evidenceFromEachValidator := make([]types.Evidence, nValidators) evidenceFromEachValidator := make([]types.Evidence, nValidators)
wg := new(sync.WaitGroup) wg := new(sync.WaitGroup)
wg.Add(4)
for i := 0; i < nValidators; i++ { for i := 0; i < nValidators; i++ {
wg.Add(1)
go func(i int) { go func(i int) {
defer wg.Done()
for msg := range blocksSubs[i].Out() { for msg := range blocksSubs[i].Out() {
block := msg.Data().(types.EventDataNewBlock).Block block := msg.Data().(types.EventDataNewBlock).Block
if len(block.Evidence.Evidence) != 0 { if len(block.Evidence.Evidence) != 0 {
evidenceFromEachValidator[i] = block.Evidence.Evidence[0] evidenceFromEachValidator[i] = block.Evidence.Evidence[0]
wg.Done()
return return
} }
} }
@ -323,8 +323,8 @@ func TestByzantineConflictingProposalsWithPartition(t *testing.T) {
// wait till everyone makes the first new block // wait till everyone makes the first new block
// (one of them already has) // (one of them already has)
wg := new(sync.WaitGroup) wg := new(sync.WaitGroup)
wg.Add(2)
for i := 1; i < N-1; i++ { for i := 1; i < N-1; i++ {
wg.Add(1)
go func(j int) { go func(j int) {
<-blocksSubs[j].Out() <-blocksSubs[j].Out()
wg.Done() wg.Done()


Loading…
Cancel
Save