session: terminates on context cancel
This commit is contained in:
+25
-4
@@ -197,10 +197,31 @@ func TestRequestManager_Session(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("terminates on context cancel", func(t *testing.T) {
|
t.Run("terminates on context cancel", func(t *testing.T) {
|
||||||
// construct a session, hold its cancel func
|
h := newMockSessionHarness()
|
||||||
// call cancel
|
s := newSession(
|
||||||
// assert terminate was called with termExternal
|
h.ctx, h.id, h.req, h.eose, h.closed, h.done,
|
||||||
// this covers the path that Cancel() exercises on the session
|
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) {
|
t.Run("terminates on closed signal", func(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user