Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: port client-connect, client-dispatch, client-errors test to node:test #2591

Merged
merged 11 commits into from
Jan 16, 2024
Prev Previous commit
Next Next commit
Update client-errors without parser error tests
  • Loading branch information
sosukesuzuki committed Jan 11, 2024
commit b36ead756ec36b63a682d9fd19a07d50dede4cd5
42 changes: 22 additions & 20 deletions test/node-test/client-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const { tspl } = require('@matteo.collina/tspl')
const { kSocket } = require('../../lib/core/symbols')
const { wrapWithAsyncIterable, maybeWrapStream, consts } = require('../utils/async-iterators')

const { closeServerAsPromise } = require('../utils/node-http')

class IteratorError extends Error {}

test('GET errors and reconnect with pipelining 1', async (t) => {
Expand All @@ -32,7 +34,7 @@ test('GET errors and reconnect with pipelining 1', async (t) => {
res.end('hello')
})
})
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 @@ -86,7 +88,7 @@ test('GET errors and reconnect with pipelining 3', async (t) => {
res.end('hello')
}
})
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 @@ -148,7 +150,7 @@ function errorAndPipelining (type) {
res.end('hello')
})
})
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 @@ -223,7 +225,7 @@ function errorAndChunkedEncodingPipelining (type) {
res.end('hello')
})
})
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 @@ -564,7 +566,7 @@ test('POST which fails should error response', async (t) => {
res.destroy()
})
})
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 @@ -659,7 +661,7 @@ test('client destroy cleanup', async (t) => {
})
})
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

server.listen(0, () => {
client = new Client(`http://localhost:${server.address().port}`)
Expand Down Expand Up @@ -689,7 +691,7 @@ test('throwing async-iterator causes error', async (t) => {
const server = createServer((req, res) => {
res.end(Buffer.alloc(4 + 1, 'a'))
})
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 @@ -723,7 +725,7 @@ test('client async-iterator destroy cleanup', async (t) => {
})
})
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

server.listen(0, () => {
client = new Client(`http://localhost:${server.address().port}`)
Expand Down Expand Up @@ -753,7 +755,7 @@ test('GET errors body', async (t) => {
res.destroy()
}, 19)
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
Expand All @@ -777,7 +779,7 @@ test('validate request body', async (t) => {
const server = createServer((req, res) => {
res.end('asd')
})
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 @@ -869,7 +871,7 @@ function socketFailWrite (type) {
const server = createServer()
server.once('request', (req, res) => {
})
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 @@ -910,7 +912,7 @@ function socketFailEndWrite (type) {
server.once('request', (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 @@ -957,7 +959,7 @@ test('queued request should not fail on socket destroy', async (t) => {
server.on('request', (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 @@ -996,7 +998,7 @@ test('queued request should fail on client destroy', async (t) => {
server.on('request', (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 @@ -1040,7 +1042,7 @@ test('retry idempotent inflight', async (t) => {
server.on('request', (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 @@ -1131,7 +1133,7 @@ test('CONNECT throws in next tick', async (t) => {
server.on('request', (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 @@ -1195,7 +1197,7 @@ test('invalid body chunk does not crash', async (t) => {
server.on('request', (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 @@ -1243,7 +1245,7 @@ test('headers overflow', (t, done) => {
})
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 All @@ -1267,7 +1269,7 @@ test('SocketError should expose socket details (net)', async (t) => {
server.once('request', (req, res) => {
res.destroy()
})
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 @@ -1301,7 +1303,7 @@ test('SocketError should expose socket details (tls)', async (t) => {
server.once('request', (req, res) => {
res.destroy()
})
t.after(server.close.bind(server))
t.after(closeServerAsPromise(server))

server.listen(0, () => {
const client = new Client(`https://localhost:${server.address().port}`, {
Expand Down