11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciif (!common.hasCrypto)
41cb0ef41Sopenharmony_ci  common.skip('missing crypto');
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ciconst http2 = require('http2');
71cb0ef41Sopenharmony_ciconst makeDuplexPair = require('../common/duplexpair');
81cb0ef41Sopenharmony_ciconst { Worker, isMainThread } = require('worker_threads');
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci// This is a variant of test-http2-generic-streams-sendfile for checking
111cb0ef41Sopenharmony_ci// that Workers can be terminated during a .respondWithFile() operation.
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciif (isMainThread) {
141cb0ef41Sopenharmony_ci  return new Worker(__filename);
151cb0ef41Sopenharmony_ci}
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci{
181cb0ef41Sopenharmony_ci  const server = http2.createServer();
191cb0ef41Sopenharmony_ci  server.on('stream', common.mustCall((stream, headers) => {
201cb0ef41Sopenharmony_ci    stream.respondWithFile(process.execPath);  // Use a large-ish file.
211cb0ef41Sopenharmony_ci  }));
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci  const { clientSide, serverSide } = makeDuplexPair();
241cb0ef41Sopenharmony_ci  server.emit('connection', serverSide);
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci  const client = http2.connect('http://localhost:80', {
271cb0ef41Sopenharmony_ci    createConnection: common.mustCall(() => clientSide)
281cb0ef41Sopenharmony_ci  });
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci  const req = client.request();
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci  req.on('response', common.mustCall((headers) => {
331cb0ef41Sopenharmony_ci    assert.strictEqual(headers[':status'], 200);
341cb0ef41Sopenharmony_ci  }));
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci  req.on('data', common.mustCall(process.exit));
371cb0ef41Sopenharmony_ci  req.on('end', common.mustNotCall());
381cb0ef41Sopenharmony_ci  req.end();
391cb0ef41Sopenharmony_ci}
40