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 fixtures = require('../common/fixtures'); 71cb0ef41Sopenharmony_ciconst tls = require('tls'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst iter = 10; 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst server = tls.createServer({ 121cb0ef41Sopenharmony_ci key: fixtures.readKey('agent2-key.pem'), 131cb0ef41Sopenharmony_ci cert: fixtures.readKey('agent2-cert.pem') 141cb0ef41Sopenharmony_ci}, common.mustCall((socket) => { 151cb0ef41Sopenharmony_ci let str = ''; 161cb0ef41Sopenharmony_ci socket.setEncoding('utf-8'); 171cb0ef41Sopenharmony_ci socket.on('data', (chunk) => { str += chunk; }); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci socket.on('end', common.mustCall(() => { 201cb0ef41Sopenharmony_ci assert.strictEqual(str, 'a'.repeat(iter - 1)); 211cb0ef41Sopenharmony_ci server.close(); 221cb0ef41Sopenharmony_ci })); 231cb0ef41Sopenharmony_ci})); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 261cb0ef41Sopenharmony_ci const client = tls.connect({ 271cb0ef41Sopenharmony_ci port: server.address().port, 281cb0ef41Sopenharmony_ci rejectUnauthorized: false 291cb0ef41Sopenharmony_ci }, common.mustCall(() => { 301cb0ef41Sopenharmony_ci assert.strictEqual(client.bufferSize, 0); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci for (let i = 1; i < iter; i++) { 331cb0ef41Sopenharmony_ci client.write('a'); 341cb0ef41Sopenharmony_ci assert.strictEqual(client.bufferSize, i); 351cb0ef41Sopenharmony_ci } 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci client.on('finish', common.mustCall(() => { 381cb0ef41Sopenharmony_ci assert.strictEqual(client.bufferSize, 0); 391cb0ef41Sopenharmony_ci })); 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci client.end(); 421cb0ef41Sopenharmony_ci })); 431cb0ef41Sopenharmony_ci})); 44