MCPcopy
hub / github.com/grpc/grpc-go / TestLeakChecker_DetectsLeak

Function TestLeakChecker_DetectsLeak

internal/leakcheck/leakcheck_test.go:136–158  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

134}
135
136func 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
160func TestLeakChecker_PassesOnCleanup(t *testing.T) {
161 TrackAsyncReporters()

Callers

nothing calls this directly

Calls 3

TrackAsyncReportersFunction · 0.85
CheckAsyncReportersFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected