|
3 | 3 | const { test } = require('node:test') |
4 | 4 | const assert = require('node:assert/strict') |
5 | 5 | const http = require('node:http') |
| 6 | +const https = require('node:https') |
6 | 7 | const { Client, Pool, errors } = require('../..') |
7 | 8 | const stream = require('node:stream') |
8 | 9 | const { createSecureServer } = require('node:http2') |
@@ -959,3 +960,91 @@ test('dispatches in expected order for http2', async (t) => { |
959 | 960 |
|
960 | 961 | await p.completed |
961 | 962 | }) |
| 963 | + |
| 964 | +test('Issue#3065 - fix bad destroy handling', async (t) => { |
| 965 | + const p = tspl(t, { plan: 4 }) |
| 966 | + const server = https.createServer(pem, (req, res) => { |
| 967 | + res.writeHead(200, { 'content-type': 'text/plain' }) |
| 968 | + res.end('ended') |
| 969 | + }) |
| 970 | + |
| 971 | + server.listen(0, () => { |
| 972 | + const client = new Client(`https://localhost:${server.address().port}`, { |
| 973 | + connect: { |
| 974 | + rejectUnauthorized: false |
| 975 | + } |
| 976 | + }) |
| 977 | + |
| 978 | + t.after(closeClientAndServerAsPromise(client, server)) |
| 979 | + |
| 980 | + const dispatches = [] |
| 981 | + const dispatches2 = [] |
| 982 | + |
| 983 | + client.once('disconnect', (...args) => { |
| 984 | + const [,, err] = args |
| 985 | + p.strictEqual(err.code, 'UND_ERR_INFO') |
| 986 | + p.strictEqual(err.message, 'servername changed') |
| 987 | + }) |
| 988 | + |
| 989 | + client.dispatch({ |
| 990 | + path: '/', |
| 991 | + method: 'POST', |
| 992 | + body: 'body' |
| 993 | + }, { |
| 994 | + onConnect () { |
| 995 | + dispatches.push('onConnect') |
| 996 | + }, |
| 997 | + onBodySent () { |
| 998 | + dispatches.push('onBodySent') |
| 999 | + }, |
| 1000 | + onResponseStarted () { |
| 1001 | + dispatches.push('onResponseStarted') |
| 1002 | + }, |
| 1003 | + onHeaders () { |
| 1004 | + dispatches.push('onHeaders') |
| 1005 | + }, |
| 1006 | + onData () { |
| 1007 | + dispatches.push('onData') |
| 1008 | + }, |
| 1009 | + onComplete () { |
| 1010 | + dispatches.push('onComplete') |
| 1011 | + p.deepStrictEqual(dispatches, ['onConnect', 'onBodySent', 'onResponseStarted', 'onHeaders', 'onData', 'onComplete']) |
| 1012 | + }, |
| 1013 | + onError (err) { |
| 1014 | + p.ifError(err) |
| 1015 | + } |
| 1016 | + }) |
| 1017 | + |
| 1018 | + client.dispatch({ |
| 1019 | + servername: 'google.com', |
| 1020 | + path: '/', |
| 1021 | + method: 'POST', |
| 1022 | + body: 'body' |
| 1023 | + }, { |
| 1024 | + onConnect () { |
| 1025 | + dispatches2.push('onConnect') |
| 1026 | + }, |
| 1027 | + onBodySent () { |
| 1028 | + dispatches2.push('onBodySent') |
| 1029 | + }, |
| 1030 | + onResponseStarted () { |
| 1031 | + dispatches2.push('onResponseStarted') |
| 1032 | + }, |
| 1033 | + onHeaders () { |
| 1034 | + dispatches2.push('onHeaders') |
| 1035 | + }, |
| 1036 | + onData () { |
| 1037 | + dispatches2.push('onData') |
| 1038 | + }, |
| 1039 | + onComplete () { |
| 1040 | + dispatches2.push('onComplete') |
| 1041 | + p.deepStrictEqual(dispatches2, ['onConnect', 'onBodySent', 'onResponseStarted', 'onHeaders', 'onData', 'onComplete']) |
| 1042 | + }, |
| 1043 | + onError (err) { |
| 1044 | + p.ifError(err) |
| 1045 | + } |
| 1046 | + }) |
| 1047 | + }) |
| 1048 | + |
| 1049 | + await p.completed |
| 1050 | +}) |
0 commit comments