Skip to content

Commit

Permalink
test: add test scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
metcoder95 committed Apr 7, 2024
1 parent ae19601 commit 0127cf1
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions test/node-test/client-dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
})

0 comments on commit 0127cf1

Please sign in to comment.