MCPcopy Index your code
hub / github.com/nodejs/node / testH2ConnectAbort

Function testH2ConnectAbort

test/parallel/test-http2-client-destroy.js:258–295  ·  view source on GitHub ↗
(secure)

Source from the content-addressed store, hash-verified

256// Destroy ClientHttpSession with AbortSignal
257{
258 function testH2ConnectAbort(secure) {
259 const server = secure ? h2.createSecureServer() : h2.createServer();
260 const controller = new AbortController();
261
262 server.on('stream', common.mustNotCall());
263 server.listen(0, common.mustCall(() => {
264 const { signal } = controller;
265 const protocol = secure ? 'https' : 'http';
266 const client = h2.connect(`${protocol}://localhost:${server.address().port}`, {
267 signal,
268 });
269 client.on('close', common.mustCall());
270 assert.strictEqual(listenerCount(signal, 'abort'), 1);
271
272 client.on('error', common.mustCall(common.mustCall((err) => {
273 assert.strictEqual(err.code, 'ABORT_ERR');
274 assert.strictEqual(err.name, 'AbortError');
275 })));
276
277 const req = client.request({}, {});
278 assert.strictEqual(listenerCount(signal, 'abort'), 1);
279
280 req.on('error', common.mustCall((err) => {
281 assert.strictEqual(err.code, 'ERR_HTTP2_STREAM_CANCEL');
282 assert.strictEqual(err.name, 'Error');
283 assert.strictEqual(req.aborted, false);
284 assert.strictEqual(req.destroyed, true);
285 }));
286 req.on('close', common.mustCall(() => server.close()));
287
288 assert.strictEqual(req.aborted, false);
289 assert.strictEqual(req.destroyed, false);
290 // Signal listener attached
291 assert.strictEqual(listenerCount(signal, 'abort'), 1);
292
293 controller.abort();
294 }));
295 }
296 testH2ConnectAbort(false);
297 testH2ConnectAbort(true);
298}

Callers 1

Calls 8

abortMethod · 0.95
listenerCountFunction · 0.85
listenMethod · 0.80
connectMethod · 0.65
addressMethod · 0.65
requestMethod · 0.65
closeMethod · 0.65
onMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…