(t *testing.T)
| 134 | } |
| 135 | |
| 136 | func TestLeakChecker_DetectsLeak(t *testing.T) { |
| 137 | TrackAsyncReporters() |
| 138 | // Safety defer: ensure we restore the default delegate even if the test crashes |
| 139 | // before CheckAsyncReporters is called. |
| 140 | defer func() { |
| 141 | internal.AsyncReporterCleanupDelegate = func(f func()) func() { return f } |
| 142 | }() |
| 143 | |
| 144 | // We utilize the internal delegate directly to simulate stats.RegisterAsyncReporter behavior. |
| 145 | noOpCleanup := func() {} |
| 146 | wrappedCleanup := internal.AsyncReporterCleanupDelegate(noOpCleanup) |
| 147 | |
| 148 | // Create a leak: We discard 'wrappedCleanup' without calling it. |
| 149 | _ = wrappedCleanup |
| 150 | tl := &testLogger{} |
| 151 | CheckAsyncReporters(tl) |
| 152 | if tl.errorCount == 0 { |
| 153 | t.Error("Expected leak checker to report a leak, but it succeeded silently.") |
| 154 | } |
| 155 | if asyncReporterTracker != nil { |
| 156 | t.Error("Expected CheckAsyncReporters to cleanup global tracker, but it was not nil.") |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | func TestLeakChecker_PassesOnCleanup(t *testing.T) { |
| 161 | TrackAsyncReporters() |
nothing calls this directly
no test coverage detected