TestDefaultCtx_ScheduleReclaim_CancelInvoked verifies the cancel hook fires exactly once when the handler goroutine finishes.
(t *testing.T)
| 68 | // TestDefaultCtx_ScheduleReclaim_CancelInvoked verifies the cancel hook fires |
| 69 | // exactly once when the handler goroutine finishes. |
| 70 | func TestDefaultCtx_ScheduleReclaim_CancelInvoked(t *testing.T) { |
| 71 | t.Parallel() |
| 72 | app, c := acquireReclaimTestCtx(t) |
| 73 | |
| 74 | var calls atomic.Int32 |
| 75 | cancel := func() { calls.Add(1) } |
| 76 | |
| 77 | handlerDone := make(chan struct{}) |
| 78 | c.ScheduleReclaim(handlerDone, cancel) |
| 79 | |
| 80 | close(handlerDone) |
| 81 | app.ReleaseCtx(c) |
| 82 | |
| 83 | require.Eventually(t, func() bool { |
| 84 | return calls.Load() == 1 && !c.IsAbandoned() |
| 85 | }, time.Second, 5*time.Millisecond, "cancel must fire once and ctx must be reclaimed") |
| 86 | } |
| 87 | |
| 88 | // TestDefaultCtx_ScheduleReclaim_NilCancel exercises the cancel==nil branch. |
| 89 | func TestDefaultCtx_ScheduleReclaim_NilCancel(t *testing.T) { |
nothing calls this directly
no test coverage detected