11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciif (!common.hasCrypto)
51cb0ef41Sopenharmony_ci  common.skip('missing crypto');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci// Issue #24984
81cb0ef41Sopenharmony_ci// 'close' event isn't emitted on a TLS connection if it's been written to
91cb0ef41Sopenharmony_ci// (but 'end' and 'finish' events are). Without a fix, this test won't exit.
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst tls = require('tls');
121cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
131cb0ef41Sopenharmony_cilet cconn = null;
141cb0ef41Sopenharmony_cilet sconn = null;
151cb0ef41Sopenharmony_cilet read_len = 0;
161cb0ef41Sopenharmony_ciconst buffer_size = 1024 * 1024;
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_cifunction test() {
191cb0ef41Sopenharmony_ci  if (cconn && sconn) {
201cb0ef41Sopenharmony_ci    cconn.resume();
211cb0ef41Sopenharmony_ci    sconn.resume();
221cb0ef41Sopenharmony_ci    sconn.end(Buffer.alloc(buffer_size));
231cb0ef41Sopenharmony_ci  }
241cb0ef41Sopenharmony_ci}
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ciconst server = tls.createServer({
271cb0ef41Sopenharmony_ci  key: fixtures.readKey('agent1-key.pem'),
281cb0ef41Sopenharmony_ci  cert: fixtures.readKey('agent1-cert.pem')
291cb0ef41Sopenharmony_ci}, (c) => {
301cb0ef41Sopenharmony_ci  c.on('close', common.mustCall(() => server.close()));
311cb0ef41Sopenharmony_ci  sconn = c;
321cb0ef41Sopenharmony_ci  test();
331cb0ef41Sopenharmony_ci}).listen(0, common.mustCall(function() {
341cb0ef41Sopenharmony_ci  tls.connect(this.address().port, {
351cb0ef41Sopenharmony_ci    rejectUnauthorized: false
361cb0ef41Sopenharmony_ci  }, common.mustCall(function() {
371cb0ef41Sopenharmony_ci    cconn = this;
381cb0ef41Sopenharmony_ci    cconn.on('data', (d) => {
391cb0ef41Sopenharmony_ci      read_len += d.length;
401cb0ef41Sopenharmony_ci      if (read_len === buffer_size) {
411cb0ef41Sopenharmony_ci        cconn.end();
421cb0ef41Sopenharmony_ci      }
431cb0ef41Sopenharmony_ci    });
441cb0ef41Sopenharmony_ci    test();
451cb0ef41Sopenharmony_ci  }));
461cb0ef41Sopenharmony_ci}));
47