11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciif (!common.hasCrypto)
51cb0ef41Sopenharmony_ci  common.skip('missing crypto');
61cb0ef41Sopenharmony_ciconst http2 = require('http2');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_cifunction testServerTimeout(setTimeoutFn) {
91cb0ef41Sopenharmony_ci  const server = http2.createServer();
101cb0ef41Sopenharmony_ci  setTimeoutFn(server);
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci  const onServerTimeout = common.mustCall((session) => {
131cb0ef41Sopenharmony_ci    session.close();
141cb0ef41Sopenharmony_ci  });
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci  server.on('stream', common.mustNotCall());
171cb0ef41Sopenharmony_ci  server.once('timeout', onServerTimeout);
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci  server.listen(0, common.mustCall(() => {
201cb0ef41Sopenharmony_ci    const url = `http://localhost:${server.address().port}`;
211cb0ef41Sopenharmony_ci    const client = http2.connect(url);
221cb0ef41Sopenharmony_ci    client.on('close', common.mustCall(() => {
231cb0ef41Sopenharmony_ci      const client2 = http2.connect(url);
241cb0ef41Sopenharmony_ci      client2.on('close', common.mustCall(() => server.close()));
251cb0ef41Sopenharmony_ci    }));
261cb0ef41Sopenharmony_ci  }));
271cb0ef41Sopenharmony_ci}
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciconst timeout = common.platformTimeout(50);
301cb0ef41Sopenharmony_citestServerTimeout((server) => server.setTimeout(timeout));
311cb0ef41Sopenharmony_citestServerTimeout((server) => server.timeout = timeout);
32