• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const {
4  hasCrypto,
5  mustCall,
6  skip
7} = require('../common');
8if (!hasCrypto)
9  skip('missing crypto');
10
11const {
12  deepStrictEqual
13} = require('assert');
14const {
15  createServer,
16  connect
17} = require('http2');
18
19const check = Buffer.from([ 1, 2, 3, 4, 5, 6, 7, 8 ]);
20
21const server = createServer();
22server.on('stream', mustCall((stream) => {
23  stream.respond();
24  stream.end('ok');
25}));
26server.on('session', mustCall((session) => {
27  session.on('ping', mustCall((payload) => {
28    deepStrictEqual(check, payload);
29  }));
30  session.ping(check, mustCall());
31}));
32server.listen(0, mustCall(() => {
33  const client = connect(`http://localhost:${server.address().port}`);
34
35  client.on('ping', mustCall((payload) => {
36    deepStrictEqual(check, payload);
37  }));
38  client.on('connect', mustCall(() => {
39    client.ping(check, mustCall());
40  }));
41
42  const req = client.request();
43  req.resume();
44  req.on('close', mustCall(() => {
45    client.close();
46    server.close();
47  }));
48}));
49