From 283877619a2491c5099bc03f3074503b286f7aab Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 17 May 2026 11:48:17 -0400 Subject: [PATCH] session: terminates on context cancel --- request_test.go | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/request_test.go b/request_test.go index 90896cf..8e48e2a 100644 --- a/request_test.go +++ b/request_test.go @@ -197,10 +197,31 @@ func TestRequestManager_Session(t *testing.T) { }) t.Run("terminates on context cancel", func(t *testing.T) { - // construct a session, hold its cancel func - // call cancel - // assert terminate was called with termExternal - // this covers the path that Cancel() exercises on the session + h := newMockSessionHarness() + s := newSession( + h.ctx, h.id, h.req, h.eose, h.closed, h.done, + h.send, h.terminate, false, nil) + go s.run() + + Eventually(t, func() bool { + select { + case <-h.sent: + return true + default: + return false + } + }, "expected initial send") + + s.Close() + + Eventually(t, func() bool { + select { + case r := <-h.terminatedWith: + return r == termExternal + default: + return false + } + }, "expected termExternal after context cancel") }) t.Run("terminates on closed signal", func(t *testing.T) {