Skip to content

Commit

Permalink
Fix race in leader election test (#216)
Browse files Browse the repository at this point in the history
* Fix race in leader election test

* simplify
  • Loading branch information
agouin authored Nov 9, 2023
1 parent 3ee62f1 commit 91b1e51
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions signer/threshold_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,17 @@ func testThresholdValidatorLeaderElection(t *testing.T, threshold, total uint8)
require.NoError(t, err)
}

quit := make(chan bool)
done := make(chan bool)

go func() {
for i := 0; true; i++ {
select {
case <-quit:
done <- true
return
default:
}
// simulate leader election
for _, l := range leaders {
l.SetLeader(nil)
Expand Down Expand Up @@ -493,8 +502,12 @@ func testThresholdValidatorLeaderElection(t *testing.T, threshold, total uint8)
}

wg.Wait()

require.True(t, success) // at least one should succeed so that the block is not missed.
}

quit <- true
<-done
}

func TestThresholdValidatorLeaderElection2of3(t *testing.T) {
Expand Down

0 comments on commit 91b1e51

Please sign in to comment.