(t *testing.T, n int, f func(int), css []*State)
| 682 | } |
| 683 | |
| 684 | func 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 | |
| 721 | func capture() { |
| 722 | trace := make([]byte, 10240000) |
no test coverage detected