session: terminates on closed signal; complete session unit tests

This commit is contained in:
Jay
2026-05-17 11:50:36 -04:00
parent 283877619a
commit 9bd16922df
2 changed files with 28 additions and 4 deletions
+3
View File
@@ -243,6 +243,9 @@ func (s *session) run() {
s.terminate(termCloseSent) s.terminate(termCloseSent)
return return
} }
case <-s.closed:
s.terminate(termReceivedClosed)
return
} }
} }
} }
+25 -4
View File
@@ -225,10 +225,31 @@ func TestRequestManager_Session(t *testing.T) {
}) })
t.Run("terminates on closed signal", func(t *testing.T) { t.Run("terminates on closed signal", func(t *testing.T) {
// construct a session with a closed signal channel h := newMockSessionHarness()
// send a value into the closed channel s := newSession(
// assert terminate was called with termReceivedClosed h.ctx, h.id, h.req, h.eose, h.closed, h.done,
// the session does not forward the message; routing is the manager's job 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")
h.closed <- struct{}{}
Eventually(t, func() bool {
select {
case r := <-h.terminatedWith:
return r == termReceivedClosed
default:
return false
}
}, "expected termReceivedClosed")
}) })
} }