diff --git a/signer/threshold_validator_test.go b/signer/threshold_validator_test.go index 89740521..4e50e5aa 100644 --- a/signer/threshold_validator_test.go +++ b/signer/threshold_validator_test.go @@ -367,24 +367,16 @@ func testThresholdValidatorLeaderElection(t *testing.T, threshold, total uint8) require.NoError(t, err) } - electChan := make(chan struct{}) - var done bool - var mu sync.Mutex - isDone := func() bool { - mu.Lock() - defer mu.Unlock() - return done - } - setDone := func() { - mu.Lock() - defer mu.Unlock() - done = true - } + quit := make(chan bool) + done := make(chan bool) go func() { for i := 0; true; i++ { - if isDone() { - break + select { + case <-quit: + done <- true + return + default: } // simulate leader election for _, l := range leaders { @@ -404,7 +396,6 @@ func testThresholdValidatorLeaderElection(t *testing.T, threshold, total uint8) // time with new leader time.Sleep(time.Duration(mrand.Intn(50)+100) * time.Millisecond) //nolint:gosec } - electChan <- struct{}{} }() // sign 20 blocks (proposal, prevote, precommit) @@ -525,8 +516,8 @@ func testThresholdValidatorLeaderElection(t *testing.T, threshold, total uint8) require.True(t, success) // at least one should succeed so that the block is not missed. } - setDone() - <-electChan + quit <- true + <-done } func TestThresholdValidatorLeaderElection2of3(t *testing.T) {