11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciif (!common.hasCrypto) 51cb0ef41Sopenharmony_ci common.skip('missing crypto'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst assert = require('assert'); 81cb0ef41Sopenharmony_ciconst { createServer, connect } = require('http2'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst messages = []; 111cb0ef41Sopenharmony_ciconst expected = [ 121cb0ef41Sopenharmony_ci 'Stream:created', 131cb0ef41Sopenharmony_ci 'Stream:error', 141cb0ef41Sopenharmony_ci 'Stream:close', 151cb0ef41Sopenharmony_ci 'Request:error', 161cb0ef41Sopenharmony_ci]; 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ciconst server = createServer(); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ciserver.on('stream', (stream) => { 211cb0ef41Sopenharmony_ci messages.push('Stream:created'); 221cb0ef41Sopenharmony_ci stream 231cb0ef41Sopenharmony_ci .on('close', () => messages.push('Stream:close')) 241cb0ef41Sopenharmony_ci .on('error', (err) => messages.push('Stream:error')) 251cb0ef41Sopenharmony_ci .respondWithFile('dont exist'); 261cb0ef41Sopenharmony_ci}); 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ciserver.listen(0); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ciconst client = connect(`http://localhost:${server.address().port}`); 311cb0ef41Sopenharmony_ciconst req = client.request(); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_cireq.on('response', common.mustNotCall()); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_cireq.on('error', () => { 361cb0ef41Sopenharmony_ci messages.push('Request:error'); 371cb0ef41Sopenharmony_ci client.close(); 381cb0ef41Sopenharmony_ci}); 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ciclient.on('close', common.mustCall(() => { 411cb0ef41Sopenharmony_ci assert.deepStrictEqual(messages, expected); 421cb0ef41Sopenharmony_ci server.close(); 431cb0ef41Sopenharmony_ci})); 44