Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
agouin committed Nov 9, 2023
1 parent 833ade9 commit 6b2cf1c
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions signer/threshold_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6b2cf1c

Please sign in to comment.