0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-http2-onping.js
James M Snell a0c1326257
http2: add ping event
Add a `Http2Session` event whenever a non-ack `PING` is received.

Fixes: https://github.com/nodejs/node/issues/18514

PR-URL: https://github.com/nodejs/node/pull/23009
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
2018-09-23 16:36:24 -07:00

49 lines
992 B
JavaScript

'use strict';
const {
hasCrypto,
mustCall,
skip
} = require('../common');
if (!hasCrypto)
skip('missing crypto');
const {
deepStrictEqual
} = 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) => {
deepStrictEqual(check, payload);
}));
session.ping(check, mustCall());
}));
server.listen(0, mustCall(() => {
const client = connect(`http://localhost:${server.address().port}`);
client.on('ping', mustCall((payload) => {
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();
}));
}));