diff --git a/test/node-test/client-dispatch.js b/test/node-test/client-dispatch.js index d780da3b7b9..55713d9ad0e 100644 --- a/test/node-test/client-dispatch.js +++ b/test/node-test/client-dispatch.js @@ -3,6 +3,7 @@ const { test } = require('node:test') const assert = require('node:assert/strict') const http = require('node:http') +const https = require('node:https') const { Client, Pool, errors } = require('../..') const stream = require('node:stream') const { createSecureServer } = require('node:http2') @@ -959,3 +960,91 @@ test('dispatches in expected order for http2', async (t) => { await p.completed }) + +test('Issue#3065 - fix bad destroy handling', async (t) => { + const p = tspl(t, { plan: 4 }) + const server = https.createServer(pem, (req, res) => { + res.writeHead(200, { 'content-type': 'text/plain' }) + res.end('ended') + }) + + server.listen(0, () => { + const client = new Client(`https://localhost:${server.address().port}`, { + connect: { + rejectUnauthorized: false + } + }) + + t.after(closeClientAndServerAsPromise(client, server)) + + const dispatches = [] + const dispatches2 = [] + + client.once('disconnect', (...args) => { + const [,, err] = args + p.strictEqual(err.code, 'UND_ERR_INFO') + p.strictEqual(err.message, 'servername changed') + }) + + client.dispatch({ + path: '/', + method: 'POST', + body: 'body' + }, { + onConnect () { + dispatches.push('onConnect') + }, + onBodySent () { + dispatches.push('onBodySent') + }, + onResponseStarted () { + dispatches.push('onResponseStarted') + }, + onHeaders () { + dispatches.push('onHeaders') + }, + onData () { + dispatches.push('onData') + }, + onComplete () { + dispatches.push('onComplete') + p.deepStrictEqual(dispatches, ['onConnect', 'onBodySent', 'onResponseStarted', 'onHeaders', 'onData', 'onComplete']) + }, + onError (err) { + p.ifError(err) + } + }) + + client.dispatch({ + servername: 'google.com', + path: '/', + method: 'POST', + body: 'body' + }, { + onConnect () { + dispatches2.push('onConnect') + }, + onBodySent () { + dispatches2.push('onBodySent') + }, + onResponseStarted () { + dispatches2.push('onResponseStarted') + }, + onHeaders () { + dispatches2.push('onHeaders') + }, + onData () { + dispatches2.push('onData') + }, + onComplete () { + dispatches2.push('onComplete') + p.deepStrictEqual(dispatches2, ['onConnect', 'onBodySent', 'onResponseStarted', 'onHeaders', 'onData', 'onComplete']) + }, + onError (err) { + p.ifError(err) + } + }) + }) + + await p.completed +})