|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +if (!common.hasCrypto) |
| 5 | + common.skip('missing crypto'); |
| 6 | + |
| 7 | +// This test ensures that the built-in HTTP/2 diagnostics channels are reporting |
| 8 | +// the diagnostics messages for the 'http2.client.stream.error' channel when |
| 9 | +// an error occurs during the processing of a ClientHttp2Stream. |
| 10 | + |
| 11 | +const assert = require('assert'); |
| 12 | +const dc = require('diagnostics_channel'); |
| 13 | +const http2 = require('http2'); |
| 14 | +const { Duplex } = require('stream'); |
| 15 | + |
| 16 | +dc.subscribe('http2.client.stream.error', common.mustCall(({ stream, error }) => { |
| 17 | + // Since ClientHttp2Stream is not exported from any module, this just checks |
| 18 | + // if the stream is an instance of Duplex and the constructor name is |
| 19 | + // 'ClientHttp2Stream'. |
| 20 | + assert.ok(stream instanceof Duplex); |
| 21 | + assert.strictEqual(stream.constructor.name, 'ClientHttp2Stream'); |
| 22 | + assert.strictEqual(stream.closed, true); |
| 23 | + assert.strictEqual(stream.destroyed, true); |
| 24 | + |
| 25 | + assert.ok(error); |
| 26 | + assert.strictEqual(error.code, 'ABORT_ERR'); |
| 27 | + assert.strictEqual(error.name, 'AbortError'); |
| 28 | +})); |
| 29 | + |
| 30 | +const server = http2.createServer(); |
| 31 | +server.listen(0, common.mustCall(() => { |
| 32 | + const port = server.address().port; |
| 33 | + const client = http2.connect(`http://localhost:${port}`); |
| 34 | + |
| 35 | + const ac = new AbortController(); |
| 36 | + const stream = client.request({}, { signal: ac.signal }); |
| 37 | + ac.abort(); |
| 38 | + |
| 39 | + stream.on('error', common.mustCall((err) => { |
| 40 | + assert.strictEqual(err.code, 'ABORT_ERR'); |
| 41 | + assert.strictEqual(err.name, 'AbortError'); |
| 42 | + |
| 43 | + client.close(); |
| 44 | + server.close(); |
| 45 | + })); |
| 46 | +})); |
0 commit comments