11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst {
41cb0ef41Sopenharmony_ci  hasCrypto,
51cb0ef41Sopenharmony_ci  mustCall,
61cb0ef41Sopenharmony_ci  skip
71cb0ef41Sopenharmony_ci} = require('../common');
81cb0ef41Sopenharmony_ciif (!hasCrypto)
91cb0ef41Sopenharmony_ci  skip('missing crypto');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst {
121cb0ef41Sopenharmony_ci  deepStrictEqual
131cb0ef41Sopenharmony_ci} = require('assert');
141cb0ef41Sopenharmony_ciconst {
151cb0ef41Sopenharmony_ci  createServer,
161cb0ef41Sopenharmony_ci  connect
171cb0ef41Sopenharmony_ci} = require('http2');
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciconst check = Buffer.from([ 1, 2, 3, 4, 5, 6, 7, 8 ]);
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ciconst server = createServer();
221cb0ef41Sopenharmony_ciserver.on('stream', mustCall((stream) => {
231cb0ef41Sopenharmony_ci  stream.respond();
241cb0ef41Sopenharmony_ci  stream.end('ok');
251cb0ef41Sopenharmony_ci}));
261cb0ef41Sopenharmony_ciserver.on('session', mustCall((session) => {
271cb0ef41Sopenharmony_ci  session.on('ping', mustCall((payload) => {
281cb0ef41Sopenharmony_ci    deepStrictEqual(check, payload);
291cb0ef41Sopenharmony_ci  }));
301cb0ef41Sopenharmony_ci  session.ping(check, mustCall());
311cb0ef41Sopenharmony_ci}));
321cb0ef41Sopenharmony_ciserver.listen(0, mustCall(() => {
331cb0ef41Sopenharmony_ci  const client = connect(`http://localhost:${server.address().port}`);
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci  client.on('ping', mustCall((payload) => {
361cb0ef41Sopenharmony_ci    deepStrictEqual(check, payload);
371cb0ef41Sopenharmony_ci  }));
381cb0ef41Sopenharmony_ci  client.on('connect', mustCall(() => {
391cb0ef41Sopenharmony_ci    client.ping(check, mustCall());
401cb0ef41Sopenharmony_ci  }));
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci  const req = client.request();
431cb0ef41Sopenharmony_ci  req.resume();
441cb0ef41Sopenharmony_ci  req.on('close', mustCall(() => {
451cb0ef41Sopenharmony_ci    client.close();
461cb0ef41Sopenharmony_ci    server.close();
471cb0ef41Sopenharmony_ci  }));
481cb0ef41Sopenharmony_ci}));
49