From 91b1e51d0ae57b6409effe2c25ababc7b5b6c730 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Wed, 8 Nov 2023 18:17:56 -0700 Subject: [PATCH] Fix race in leader election test (#216) * Fix race in leader election test * simplify --- signer/threshold_validator_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/signer/threshold_validator_test.go b/signer/threshold_validator_test.go index 92718bab..fad60da5 100644 --- a/signer/threshold_validator_test.go +++ b/signer/threshold_validator_test.go @@ -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) @@ -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) {