Fixed tests.

pull/4509/head
frozen 2 years ago committed by Casey Gardiner
parent d1a0e9cbf2
commit 69ae68c744
  1. 6
      consensus/consensus_service.go
  2. 17
      internal/utils/singleton.go

@ -442,7 +442,11 @@ func (consensus *Consensus) UpdateConsensusInformation() Mode {
// IsLeader check if the node is a leader or not by comparing the public key of
// the node with the leader public key
func (consensus *Consensus) IsLeader() bool {
consensus.mutex.RLock()
_ = utils.AssertNoLongerThan0(5*time.Second, func() error {
consensus.mutex.RLock()
return nil
})
defer consensus.mutex.RUnlock()
return consensus.isLeader()

@ -6,6 +6,7 @@ import (
"fmt"
"os"
"path"
"runtime/debug"
"strconv"
"sync"
"time"
@ -213,3 +214,19 @@ func GetPort() int {
}
return 0
}
func AssertNoLongerThan0[E any](t time.Duration, f func() E) E {
ch := make(chan E)
defer close(ch)
stack := debug.Stack()
go func() {
select {
case <-time.After(t):
panic("AssertNoLongerThan0: " + string(stack))
case <-ch:
return
}
}()
return f()
}

Loading…
Cancel
Save