v1rtl
v1rtl2y ago

Closing a websocket server in a unit test

Hello, I'm an author of rpc lib and I'm currently writing unit tests for it. I am facing a problem of closing a server. How should I do it without deno hanging forever? my test case:
import { send, App } from './mod.ts'

Deno.test('send', async (t) => {
await t.step('should send a message with websocket', async () => {
const app = new App()
await app.listen({ port: 8881, hostname: 'localhost' })

const socket = new WebSocket('ws://localhost:8881')
socket.onopen = () => {
send(socket, { hello: 'world' })
socket.close()
app.close()
}
})
})
import { send, App } from './mod.ts'

Deno.test('send', async (t) => {
await t.step('should send a message with websocket', async () => {
const app = new App()
await app.listen({ port: 8881, hostname: 'localhost' })

const socket = new WebSocket('ws://localhost:8881')
socket.onopen = () => {
send(socket, { hello: 'world' })
socket.close()
app.close()
}
})
})
app.listen here both starts the Deno.listener and Deno.serveHttp
GitHub
GitHub - deno-libs/rpc: 📡 JSONRPC server implementation for Deno
📡 JSONRPC server implementation for Deno. Contribute to deno-libs/rpc development by creating an account on GitHub.
0 Replies
No replies yetBe the first to reply to this messageJoin