diff --git a/test/http2-agent.js b/test/http2-agent.js index 14c3850f070..23729410d85 100644 --- a/test/http2-agent.js +++ b/test/http2-agent.js @@ -37,6 +37,12 @@ test('Agent should support H2 connection', async t => { }) after(() => client.close()) + client.on('disconnect', () => { + if (!client.closed && !client.destroyed) { + t.fail('unexpected disconnect') + } + }) + const response = await client.request({ origin: `https://localhost:${server.address().port}`, path: '/', diff --git a/test/http2-alpn.js b/test/http2-alpn.js index 840d77a83c1..4a1b8346435 100644 --- a/test/http2-alpn.js +++ b/test/http2-alpn.js @@ -63,6 +63,12 @@ test('Should upgrade to HTTP/2 when HTTPS/1 is available for GET', async (t) => // close the client on teardown after(() => client.close()) + client.on('disconnect', () => { + if (!client.closed && !client.destroyed) { + t.fail('unexpected disconnect') + } + }) + // make an undici request using where it wants http/2 const response = await client.request({ path: '/', @@ -211,6 +217,12 @@ test('Should upgrade to HTTP/2 when HTTPS/1 is available for POST', async (t) => // close the client on teardown after(() => client.close()) + client.on('disconnect', () => { + if (!client.closed && !client.destroyed) { + t.fail('unexpected disconnect') + } + }) + // make an undici request using where it wants http/2 const response = await client.request({ path: '/', diff --git a/test/http2-dispatcher.js b/test/http2-dispatcher.js index f5e0816e249..95b1d18db5b 100644 --- a/test/http2-dispatcher.js +++ b/test/http2-dispatcher.js @@ -45,6 +45,12 @@ test('Dispatcher#Stream', async t => { }) after(() => client.close()) + client.on('disconnect', () => { + if (!client.closed && !client.destroyed) { + t.fail('unexpected disconnect') + } + }) + await client.stream( { path: '/', opaque: { bufs }, method: 'POST', body: expectedBody }, ({ statusCode, headers, opaque: { bufs } }) => { @@ -99,6 +105,12 @@ test('Dispatcher#Pipeline', async t => { }) after(() => client.close()) + client.on('disconnect', () => { + if (!client.closed && !client.destroyed) { + t.fail('unexpected disconnect') + } + }) + pipeline( new Readable({ read () { @@ -159,6 +171,12 @@ test('Dispatcher#Connect', async t => { }) after(() => forward.close()) + forward.on('disconnect', () => { + if (!forward.closed && !forward.destroyed) { + t.fail('unexpected disconnect') + } + }) + try { const response = await forward.request({ path: '/', @@ -206,6 +224,12 @@ test('Dispatcher#Connect', async t => { after(() => proxy.close()) after(() => server.close()) + client.on('disconnect', () => { + if (!client.closed && !client.destroyed) { + t.fail('unexpected disconnect') + } + }) + const { statusCode, headers, socket } = await client.connect({ path: '/', headers: { 'x-my-header': 'foo' } }) t.strictEqual(statusCode, 200) t.strictEqual(headers['x-my-header'], 'foo') @@ -589,6 +613,12 @@ test('Should handle h2 request without body', async t => { }) after(() => client.close()) + client.on('disconnect', () => { + if (!client.closed && !client.destroyed) { + t.fail('unexpected disconnect') + } + }) + const response = await client.request({ path: '/', method: 'POST', @@ -635,6 +665,12 @@ test('Should clear h2 request stream references before completing a response', a }) after(() => client.close()) + client.on('disconnect', () => { + if (!client.closed && !client.destroyed) { + t.fail('unexpected disconnect') + } + }) + let requestStreamIdSymbol = null let requestStreamSymbol = null let requestStreamCleanupSymbol = null @@ -925,6 +961,12 @@ test('Should send http2 PING frames', async t => { server.close() }) + client.on('disconnect', () => { + if (!client.closed && !client.destroyed) { + t.fail('unexpected disconnect') + } + }) + client.dispatch({ path: '/', method: 'PUT', @@ -996,6 +1038,12 @@ test('Should not send http2 PING frames if interval === 0', async t => { server.close() }) + client.on('disconnect', () => { + if (!client.closed && !client.destroyed) { + t.fail('unexpected disconnect') + } + }) + client.dispatch({ path: '/', method: 'PUT', @@ -1068,6 +1116,12 @@ test('Should not send http2 PING frames after connection is closed', async t => server.close() }) + client.on('disconnect', () => { + if (!client.closed && !client.destroyed) { + t.fail('unexpected disconnect') + } + }) + client.dispatch({ path: '/', method: 'PUT', diff --git a/test/http2-trailers.js b/test/http2-trailers.js index 21919aba5d9..36e398adde4 100644 --- a/test/http2-trailers.js +++ b/test/http2-trailers.js @@ -1,7 +1,7 @@ 'use strict' -const assert = require('node:assert') -const { test } = require('node:test') +const { tspl } = require('@matteo.collina/tspl') +const { test, after } = require('node:test') const { createSecureServer } = require('node:http2') const { once } = require('node:events') @@ -10,10 +10,12 @@ const pem = require('@metcoder95/https-pem') const { Client } = require('..') test('Should handle http2 trailers', async t => { + t = tspl(t, { plan: 4 }) + const server = createSecureServer(pem) let client = null - t.after(async () => { + after(async () => { await client?.close() await new Promise(resolve => server.close(resolve)) }) @@ -44,14 +46,22 @@ test('Should handle http2 trailers', async t => { allowH2: true }) + client.on('disconnect', () => { + if (!client.closed && !client.destroyed) { + t.fail('unexpected disconnect') + } + }) + const { statusCode, headers, body, trailers } = await client.request({ path: '/', method: 'PUT', body: 'hello' }) - assert.strictEqual(statusCode, 200) - assert.strictEqual(headers['content-type'], 'text/plain; charset=utf-8') - assert.strictEqual(await body.text(), 'hello h2!') - assert.deepStrictEqual(trailers, { 'x-trailer': 'hello' }) + t.strictEqual(statusCode, 200) + t.strictEqual(headers['content-type'], 'text/plain; charset=utf-8') + t.strictEqual(await body.text(), 'hello h2!') + t.deepStrictEqual(trailers, { 'x-trailer': 'hello' }) + + await t.completed })