diff options
Diffstat (limited to 'test/diagnostics-channel/error.js')
-rw-r--r-- | test/diagnostics-channel/error.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test/diagnostics-channel/error.js b/test/diagnostics-channel/error.js new file mode 100644 index 0000000..1f350b1 --- /dev/null +++ b/test/diagnostics-channel/error.js @@ -0,0 +1,52 @@ +'use strict' + +const t = require('tap') + +let diagnosticsChannel + +try { + diagnosticsChannel = require('diagnostics_channel') +} catch { + t.skip('missing diagnostics_channel') + process.exit(0) +} + +const { Client } = require('../..') +const { createServer } = require('http') + +t.plan(3) + +const server = createServer((req, res) => { + res.destroy() +}) +t.teardown(server.close.bind(server)) + +const reqHeaders = { + foo: undefined, + bar: 'bar' +} + +let _req +diagnosticsChannel.channel('undici:request:create').subscribe(({ request }) => { + _req = request +}) + +diagnosticsChannel.channel('undici:request:error').subscribe(({ request, error }) => { + t.equal(_req, request) + t.equal(error.code, 'UND_ERR_SOCKET') +}) + +server.listen(0, () => { + const client = new Client(`http://localhost:${server.address().port}`, { + keepAliveTimeout: 300e3 + }) + t.teardown(client.close.bind(client)) + + client.request({ + path: '/', + method: 'GET', + headers: reqHeaders + }, (err, data) => { + t.equal(err.code, 'UND_ERR_SOCKET') + }) +}) |