session: sends CLOSE and terminates on EOSE if query
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/base32"
|
"encoding/base32"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.wisehodl.dev/jay/go-mana-component"
|
"git.wisehodl.dev/jay/go-mana-component"
|
||||||
|
"git.wisehodl.dev/jay/go-roots-ws"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -237,6 +238,11 @@ func (s *session) run() {
|
|||||||
s.terminate(termExternal)
|
s.terminate(termExternal)
|
||||||
return
|
return
|
||||||
case <-s.eose:
|
case <-s.eose:
|
||||||
|
if s.closeOnEOSE {
|
||||||
|
s.send(envelope.EncloseClose(s.id))
|
||||||
|
s.terminate(termCloseSent)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+38
-4
@@ -138,10 +138,44 @@ func TestRequestManager_Session(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("sends close on eose if query", func(t *testing.T) {
|
t.Run("sends close on eose if query", func(t *testing.T) {
|
||||||
// construct a session with closeOnEOSE = true
|
h := newMockSessionHarness()
|
||||||
// send a value into the eose channel
|
s := newSession(
|
||||||
// assert the mock send was called with a CLOSE envelope for the session id
|
h.ctx, h.id, h.req, h.eose, h.closed, h.done,
|
||||||
// assert terminate was called with termCloseSent
|
h.send, h.terminate, true, nil)
|
||||||
|
go s.run()
|
||||||
|
|
||||||
|
// drain initial REQ send
|
||||||
|
Eventually(t, func() bool {
|
||||||
|
select {
|
||||||
|
case <-h.sent:
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}, "expected initial REQ send")
|
||||||
|
|
||||||
|
h.eose <- struct{}{}
|
||||||
|
|
||||||
|
var got []byte
|
||||||
|
Eventually(t, func() bool {
|
||||||
|
select {
|
||||||
|
case got = <-h.sent:
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}, "expected CLOSE send")
|
||||||
|
|
||||||
|
assert.Equal(t, []byte(envelope.EncloseClose(h.id)), got)
|
||||||
|
|
||||||
|
Eventually(t, func() bool {
|
||||||
|
select {
|
||||||
|
case r := <-h.terminatedWith:
|
||||||
|
return r == termCloseSent
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}, "expected termCloseSent")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("terminates on done close", func(t *testing.T) {
|
t.Run("terminates on done close", func(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user