(t *testing.T)
| 69 | } |
| 70 | |
| 71 | func TestCheckRegisterIgnore(t *testing.T) { |
| 72 | RegisterIgnoreGoroutine("ignoredTestingLeak") |
| 73 | go ignoredTestingLeak(3 * time.Second) |
| 74 | const leakCount = 3 |
| 75 | ch := make(chan struct{}) |
| 76 | for i := 0; i < leakCount; i++ { |
| 77 | go func() { <-ch }() |
| 78 | } |
| 79 | if leaked := interestingGoroutines(); len(leaked) != leakCount { |
| 80 | t.Errorf("interestingGoroutines() = %d, want length %d", len(leaked), leakCount) |
| 81 | } |
| 82 | e := &testLogger{} |
| 83 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) |
| 84 | defer cancel() |
| 85 | if CheckGoroutines(ctx, e); e.errorCount < leakCount { |
| 86 | t.Errorf("CheckGoroutines() = %d, want count %d", e.errorCount, leakCount) |
| 87 | t.Logf("leaked goroutines:\n%v", strings.Join(e.errors, "\n")) |
| 88 | } |
| 89 | close(ch) |
| 90 | ctx, cancel = context.WithTimeout(context.Background(), 3*time.Second) |
| 91 | defer cancel() |
| 92 | CheckGoroutines(ctx, t) |
| 93 | } |
| 94 | |
| 95 | // TestTrackTimers verifies that only leaked timers are reported and expired, |
| 96 | // stopped timers are ignored. |
nothing calls this directly
no test coverage detected