mirror of
https://github.com/stablyai/orca.git
synced 2026-10-26 16:02:42 +00:00
test: cover daemon hello close races
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -48,6 +48,8 @@ describe('DaemonClient', () => {
|
||||
})
|
||||
|
||||
function startMockDaemon(opts?: {
|
||||
closeOnConnect?: boolean
|
||||
closeOnHello?: boolean
|
||||
onControlMessage?: (msg: unknown) => string | null
|
||||
onHello?: (msg: HelloMessage) => void
|
||||
onStreamHello?: (msg: HelloMessage) => void
|
||||
@@ -56,6 +58,11 @@ describe('DaemonClient', () => {
|
||||
}): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
server = createServer((socket) => {
|
||||
if (opts?.closeOnConnect) {
|
||||
socket.destroy()
|
||||
return
|
||||
}
|
||||
|
||||
let buffer = ''
|
||||
socket.on('data', (chunk) => {
|
||||
buffer += chunk.toString()
|
||||
@@ -72,6 +79,10 @@ describe('DaemonClient', () => {
|
||||
if (msg.type === 'hello') {
|
||||
const hello = msg as HelloMessage
|
||||
opts?.onHello?.(hello)
|
||||
if (opts?.closeOnHello) {
|
||||
socket.destroy()
|
||||
return
|
||||
}
|
||||
if (opts?.suppressHelloResponse) {
|
||||
return
|
||||
}
|
||||
@@ -164,6 +175,22 @@ describe('DaemonClient', () => {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('rejects when the daemon closes before hello completes', async () => {
|
||||
await startMockDaemon({ closeOnHello: true })
|
||||
|
||||
client = new DaemonClient({ socketPath, tokenPath })
|
||||
await expect(client.ensureConnected()).rejects.toThrow(
|
||||
'Connection closed before hello response'
|
||||
)
|
||||
})
|
||||
|
||||
it('rejects when the daemon closes immediately after connect', async () => {
|
||||
await startMockDaemon({ closeOnConnect: true })
|
||||
|
||||
client = new DaemonClient({ socketPath, tokenPath })
|
||||
await expect(client.ensureConnected()).rejects.toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe('RPC', () => {
|
||||
|
||||
Reference in New Issue
Block a user