TestDrainErrGroupReturnsError verifies the normal path: when the group's goroutines finish before the timeout, DrainErrGroup returns g.Wait()'s error verbatim (and does not wait out the timeout).
(t *testing.T)
| 13 | // goroutines finish before the timeout, DrainErrGroup returns g.Wait()'s error |
| 14 | // verbatim (and does not wait out the timeout). |
| 15 | func TestDrainErrGroupReturnsError(t *testing.T) { |
| 16 | var g errgroup.Group |
| 17 | want := errors.New("boom") |
| 18 | g.Go(func() error { return want }) |
| 19 | |
| 20 | start := time.Now() |
| 21 | got := DrainErrGroup(zap.NewNop(), "test", &g, time.Second) |
| 22 | if !errors.Is(got, want) { |
| 23 | t.Fatalf("DrainErrGroup err = %v, want %v", got, want) |
| 24 | } |
| 25 | if elapsed := time.Since(start); elapsed > 500*time.Millisecond { |
| 26 | t.Fatalf("DrainErrGroup blocked for %s on a fast group; should return immediately", elapsed) |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | // TestDrainErrGroupTimesOutOnHang is the regression guard for the shutdown |
| 31 | // deadlock: a goroutine that ignores cancellation (here, blocks forever) must |
nothing calls this directly
no test coverage detected