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 h2 = require('http2');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci// Errors should not be reported both in Http2ServerRequest
91cb0ef41Sopenharmony_ci// and Http2ServerResponse
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ci{
121cb0ef41Sopenharmony_ci  let expected = null;
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci  const server = h2.createServer();
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci  server.on('stream', common.mustCall(function(stream) {
171cb0ef41Sopenharmony_ci    stream.on('error', common.mustCall(function(err) {
181cb0ef41Sopenharmony_ci      assert.strictEqual(err, expected);
191cb0ef41Sopenharmony_ci    }));
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci    stream.resume();
221cb0ef41Sopenharmony_ci    stream.write('hello');
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci    expected = new Error('kaboom');
251cb0ef41Sopenharmony_ci    stream.destroy(expected);
261cb0ef41Sopenharmony_ci    server.close();
271cb0ef41Sopenharmony_ci  }));
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci  server.listen(0, common.mustCall(function() {
301cb0ef41Sopenharmony_ci    const port = server.address().port;
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci    const url = `http://localhost:${port}`;
331cb0ef41Sopenharmony_ci    const client = h2.connect(url, common.mustCall(function() {
341cb0ef41Sopenharmony_ci      const headers = {
351cb0ef41Sopenharmony_ci        ':path': '/foobar',
361cb0ef41Sopenharmony_ci        ':method': 'GET',
371cb0ef41Sopenharmony_ci        ':scheme': 'http',
381cb0ef41Sopenharmony_ci        ':authority': `localhost:${port}`,
391cb0ef41Sopenharmony_ci      };
401cb0ef41Sopenharmony_ci      const request = client.request(headers);
411cb0ef41Sopenharmony_ci      request.on('data', common.mustCall(function(chunk) {
421cb0ef41Sopenharmony_ci        // Cause an error on the server side
431cb0ef41Sopenharmony_ci        client.destroy();
441cb0ef41Sopenharmony_ci      }));
451cb0ef41Sopenharmony_ci      request.end();
461cb0ef41Sopenharmony_ci    }));
471cb0ef41Sopenharmony_ci  }));
481cb0ef41Sopenharmony_ci}
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci{
511cb0ef41Sopenharmony_ci  let expected = null;
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ci  const server = h2.createServer();
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci  process.on('uncaughtException', common.mustCall(function(err) {
561cb0ef41Sopenharmony_ci    assert.strictEqual(err.message, 'kaboom no handler');
571cb0ef41Sopenharmony_ci  }));
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci  server.on('stream', common.mustCall(function(stream) {
601cb0ef41Sopenharmony_ci    // There is no 'error'  handler, and this will crash
611cb0ef41Sopenharmony_ci    stream.write('hello');
621cb0ef41Sopenharmony_ci    stream.resume();
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_ci    expected = new Error('kaboom no handler');
651cb0ef41Sopenharmony_ci    stream.destroy(expected);
661cb0ef41Sopenharmony_ci    server.close();
671cb0ef41Sopenharmony_ci  }));
681cb0ef41Sopenharmony_ci
691cb0ef41Sopenharmony_ci  server.listen(0, common.mustCall(function() {
701cb0ef41Sopenharmony_ci    const port = server.address().port;
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_ci    const url = `http://localhost:${port}`;
731cb0ef41Sopenharmony_ci    const client = h2.connect(url, common.mustCall(function() {
741cb0ef41Sopenharmony_ci      const headers = {
751cb0ef41Sopenharmony_ci        ':path': '/foobar',
761cb0ef41Sopenharmony_ci        ':method': 'GET',
771cb0ef41Sopenharmony_ci        ':scheme': 'http',
781cb0ef41Sopenharmony_ci        ':authority': `localhost:${port}`,
791cb0ef41Sopenharmony_ci      };
801cb0ef41Sopenharmony_ci      const request = client.request(headers);
811cb0ef41Sopenharmony_ci      request.on('data', common.mustCall(function(chunk) {
821cb0ef41Sopenharmony_ci        // Cause an error on the server side
831cb0ef41Sopenharmony_ci        client.destroy();
841cb0ef41Sopenharmony_ci      }));
851cb0ef41Sopenharmony_ci      request.end();
861cb0ef41Sopenharmony_ci    }));
871cb0ef41Sopenharmony_ci  }));
881cb0ef41Sopenharmony_ci}
89