MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / timeoutWaitGroup

Function timeoutWaitGroup

consensus/reactor_test.go:684–719  ·  view source on GitHub ↗
(t *testing.T, n int, f func(int), css []*State)

Source from the content-addressed store, hash-verified

682}
683
684func timeoutWaitGroup(t *testing.T, n int, f func(int), css []*State) {
685 wg := new(sync.WaitGroup)
686 wg.Add(n)
687 for i := 0; i < n; i++ {
688 go func(j int) {
689 f(j)
690 wg.Done()
691 }(i)
692 }
693
694 done := make(chan struct{})
695 go func() {
696 wg.Wait()
697 close(done)
698 }()
699
700 // we're running many nodes in-process, possibly in in a virtual machine,
701 // and spewing debug messages - making a block could take a while,
702 timeout := time.Second * 120
703
704 select {
705 case <-done:
706 case <-time.After(timeout):
707 for i, cs := range css {
708 t.Log("#################")
709 t.Log("Validator", i)
710 t.Log(cs.GetRoundState())
711 t.Log("")
712 }
713 os.Stdout.Write([]byte("pprof.Lookup('goroutine'):\n"))
714 err := pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
715 require.NoError(t, err)
716 capture()
717 panic("Timed out waiting for all validators to commit a block")
718 }
719}
720
721func capture() {
722 trace := make([]byte, 10240000)

Calls 7

captureFunction · 0.85
LogMethod · 0.80
DoneMethod · 0.65
WaitMethod · 0.65
WriteMethod · 0.65
AddMethod · 0.45
GetRoundStateMethod · 0.45

Tested by

no test coverage detected