11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci// Verifies that write callbacks are called
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst common = require('../common');
61cb0ef41Sopenharmony_ciif (!common.hasCrypto)
71cb0ef41Sopenharmony_ci  common.skip('missing crypto');
81cb0ef41Sopenharmony_ciconst assert = require('assert');
91cb0ef41Sopenharmony_ciconst http2 = require('http2');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst server = http2.createServer();
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciserver.on('stream', common.mustCall((stream) => {
141cb0ef41Sopenharmony_ci  stream.write('abc', common.mustCall(() => {
151cb0ef41Sopenharmony_ci    stream.end('xyz');
161cb0ef41Sopenharmony_ci  }));
171cb0ef41Sopenharmony_ci  let actual = '';
181cb0ef41Sopenharmony_ci  stream.setEncoding('utf8');
191cb0ef41Sopenharmony_ci  stream.on('data', (chunk) => actual += chunk);
201cb0ef41Sopenharmony_ci  stream.on('end', common.mustCall(() => assert.strictEqual(actual, 'abcxyz')));
211cb0ef41Sopenharmony_ci}));
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => {
241cb0ef41Sopenharmony_ci  const client = http2.connect(`http://localhost:${server.address().port}`);
251cb0ef41Sopenharmony_ci  const req = client.request({ ':method': 'POST' });
261cb0ef41Sopenharmony_ci  req.write('abc', common.mustCall(() => {
271cb0ef41Sopenharmony_ci    req.end('xyz');
281cb0ef41Sopenharmony_ci  }));
291cb0ef41Sopenharmony_ci  let actual = '';
301cb0ef41Sopenharmony_ci  req.setEncoding('utf8');
311cb0ef41Sopenharmony_ci  req.on('data', (chunk) => actual += chunk);
321cb0ef41Sopenharmony_ci  req.on('end', common.mustCall(() => assert.strictEqual(actual, 'abcxyz')));
331cb0ef41Sopenharmony_ci  req.on('close', common.mustCall(() => {
341cb0ef41Sopenharmony_ci    client.close();
351cb0ef41Sopenharmony_ci    server.close();
361cb0ef41Sopenharmony_ci  }));
371cb0ef41Sopenharmony_ci}));
38