Files
node/test/parallel/test-http2-onping.js
Antoine du Hamel ecbc22dc37 test: ensure assertions are reached on HTTP2 tests
PR-URL: https://github.com/nodejs/node/pull/60730
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2025-11-17 21:34:43 +01:00

47 lines
991 B
JavaScript

'use strict';
const {
hasCrypto,
mustCall,
skip
} = require('../common');
if (!hasCrypto)
skip('missing crypto');
const assert = require('assert');
const {
createServer,
connect
} = require('http2');
const check = Buffer.from([ 1, 2, 3, 4, 5, 6, 7, 8 ]);
const server = createServer();
server.on('stream', mustCall((stream) => {
stream.respond();
stream.end('ok');
}));
server.on('session', mustCall((session) => {
session.on('ping', mustCall((payload) => {
assert.deepStrictEqual(check, payload);
}));
session.ping(check, mustCall());
}));
server.listen(0, mustCall(() => {
const client = connect(`http://localhost:${server.address().port}`);
client.on('ping', mustCall((payload) => {
assert.deepStrictEqual(check, payload);
}));
client.on('connect', mustCall(() => {
client.ping(check, mustCall());
}));
const req = client.request();
req.resume();
req.on('close', mustCall(() => {
client.close();
server.close();
}));
}));