TestDrainErrGroupTimesOutOnHang is the regression guard for the shutdown deadlock: a goroutine that ignores cancellation (here, blocks forever) must NOT be able to make DrainErrGroup block past its timeout. Without the bound, the teardown that calls this would hang until an external SIGKILL.
(t *testing.T)
| 32 | // NOT be able to make DrainErrGroup block past its timeout. Without the bound, |
| 33 | // the teardown that calls this would hang until an external SIGKILL. |
| 34 | func TestDrainErrGroupTimesOutOnHang(t *testing.T) { |
| 35 | var g errgroup.Group |
| 36 | block := make(chan struct{}) |
| 37 | g.Go(func() error { |
| 38 | <-block // simulates a goroutine that never observes context cancellation |
| 39 | return nil |
| 40 | }) |
| 41 | |
| 42 | start := time.Now() |
| 43 | got := DrainErrGroup(zap.NewNop(), "test", &g, 50*time.Millisecond) |
| 44 | elapsed := time.Since(start) |
| 45 | |
| 46 | if got != nil { |
| 47 | t.Fatalf("DrainErrGroup err = %v, want nil on timeout", got) |
| 48 | } |
| 49 | if elapsed > 2*time.Second { |
| 50 | t.Fatalf("DrainErrGroup did not return promptly on a hung group: took %s (the deadlock would persist)", elapsed) |
| 51 | } |
| 52 | close(block) // unblock the leaked goroutine so the test process stays clean |
| 53 | } |
nothing calls this directly
no test coverage detected