Skip to content

Commit

Permalink
Use closeServerAsPromise for client-dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki committed Jan 11, 2024
1 parent 159c39c commit eca036c
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions test/node-test/client-dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const stream = require('stream')
const { createSecureServer } = require('node:http2')
const pem = require('https-pem')
const { tspl } = require('@matteo.collina/tspl')
const { closeServerAsPromise, closeClientAndServerAsPromise } = require('../utils/node-http')

test('dispatch invalid opts', (t) => {
const p = tspl(t, { plan: 14 })
Expand Down Expand Up @@ -102,7 +103,7 @@ test('basic dispatch get', async (t) => {
p.strictEqual(undefined, req.headers['content-length'])
res.end('hello')
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

const reqHeaders = {
foo: undefined,
Expand Down Expand Up @@ -157,7 +158,7 @@ test('trailers dispatch get', async (t) => {
res.setHeader('Trailer', 'Content-MD5')
res.end('hello')
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

const reqHeaders = {
foo: undefined,
Expand Down Expand Up @@ -210,7 +211,7 @@ test('dispatch onHeaders error', async (t) => {
const server = http.createServer((req, res) => {
res.end()
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
Expand Down Expand Up @@ -247,7 +248,7 @@ test('dispatch onComplete error', async (t) => {
const server = http.createServer((req, res) => {
res.end()
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
Expand Down Expand Up @@ -284,7 +285,7 @@ test('dispatch onData error', async (t) => {
const server = http.createServer((req, res) => {
res.end('ad')
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
Expand Down Expand Up @@ -321,7 +322,7 @@ test('dispatch onConnect error', async (t) => {
const server = http.createServer((req, res) => {
res.end('ad')
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
Expand Down Expand Up @@ -371,7 +372,7 @@ test('connect call onUpgrade once', async (t) => {
socket.end(data)
})
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

server.listen(0, async () => {
const client = new Client(`http://localhost:${server.address().port}`)
Expand Down Expand Up @@ -423,7 +424,7 @@ test('dispatch onConnect missing', async (t) => {
const server = http.createServer((req, res) => {
res.end('ad')
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
Expand Down Expand Up @@ -457,7 +458,7 @@ test('dispatch onHeaders missing', async (t) => {
const server = http.createServer((req, res) => {
res.end('ad')
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
Expand Down Expand Up @@ -490,7 +491,7 @@ test('dispatch onData missing', async (t) => {
const server = http.createServer((req, res) => {
res.end('ad')
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
Expand Down Expand Up @@ -523,7 +524,7 @@ test('dispatch onComplete missing', async (t) => {
const server = http.createServer((req, res) => {
res.end('ad')
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
Expand Down Expand Up @@ -556,7 +557,7 @@ test('dispatch onError missing', async (t) => {
const server = http.createServer((req, res) => {
res.end('ad')
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
Expand Down Expand Up @@ -593,7 +594,7 @@ test('dispatch CONNECT onUpgrade missing', async (t) => {
const server = http.createServer((req, res) => {
res.end('ad')
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
Expand Down Expand Up @@ -624,7 +625,7 @@ test('dispatch upgrade onUpgrade missing', async (t) => {
const server = http.createServer((req, res) => {
res.end('ad')
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
Expand Down Expand Up @@ -655,7 +656,7 @@ test('dispatch pool onError missing', async (t) => {
const server = http.createServer((req, res) => {
res.end('ad')
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

server.listen(0, () => {
const client = new Pool(`http://localhost:${server.address().port}`)
Expand All @@ -682,7 +683,7 @@ test('dispatch onBodySent not a function', async (t) => {
const server = http.createServer((req, res) => {
res.end('ad')
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

server.listen(0, () => {
const client = new Pool(`http://localhost:${server.address().port}`)
Expand Down Expand Up @@ -712,7 +713,7 @@ test('dispatch onBodySent buffer', async (t) => {
const server = http.createServer((req, res) => {
res.end('ad')
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

server.listen(0, () => {
const client = new Pool(`http://localhost:${server.address().port}`)
Expand Down Expand Up @@ -749,7 +750,7 @@ test('dispatch onBodySent stream', async (t) => {
const server = http.createServer((req, res) => {
res.end('ad')
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))
const chunks = ['he', 'llo', 'world', '🚀']
const toSendBytes = chunks.reduce((a, b) => a + Buffer.byteLength(b), 0)
const body = stream.Readable.from(chunks)
Expand Down Expand Up @@ -791,7 +792,7 @@ test('dispatch onBodySent async-iterable', (t, done) => {
const server = http.createServer((req, res) => {
res.end('ad')
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))
const chunks = ['he', 'llo', 'world', '🚀']
const toSendBytes = chunks.reduce((a, b) => a + Buffer.byteLength(b), 0)
server.listen(0, () => {
Expand Down Expand Up @@ -827,7 +828,7 @@ test('dispatch onBodySent throws error', (t, done) => {
const server = http.createServer((req, res) => {
res.end('ended')
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

server.listen(0, () => {
const client = new Pool(`http://localhost:${server.address().port}`)
Expand Down Expand Up @@ -858,7 +859,7 @@ test('dispatches in expected order', async (t) => {
const server = http.createServer((req, res) => {
res.end('ended')
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

const p = tspl(t, { plan: 1 })

Expand Down Expand Up @@ -912,8 +913,6 @@ test('dispatches in expected order for http2', async (t) => {
stream.end('ended')
})

t.after(server.close.bind(server))

const p = tspl(t, { plan: 1 })

server.listen(0, () => {
Expand All @@ -924,7 +923,7 @@ test('dispatches in expected order for http2', async (t) => {
allowH2: true
})

t.after(() => { return client.close() })
t.after(closeClientAndServerAsPromise(client, server))

const dispatches = []

Expand Down

0 comments on commit eca036c

Please sign in to comment.