11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst http = require('http');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst onWriteAfterEndError = common.mustCall((err) => {
71cb0ef41Sopenharmony_ci  assert.strictEqual(err.code, 'ERR_STREAM_WRITE_AFTER_END');
81cb0ef41Sopenharmony_ci}, 2);
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciconst server = http.createServer(common.mustCall(function(req, res) {
111cb0ef41Sopenharmony_ci  res.end('testing ended state', common.mustCall());
121cb0ef41Sopenharmony_ci  assert.strictEqual(res.writableCorked, 0);
131cb0ef41Sopenharmony_ci  res.end(common.mustCall((err) => {
141cb0ef41Sopenharmony_ci    assert.strictEqual(err.code, 'ERR_STREAM_ALREADY_FINISHED');
151cb0ef41Sopenharmony_ci  }));
161cb0ef41Sopenharmony_ci  assert.strictEqual(res.writableCorked, 0);
171cb0ef41Sopenharmony_ci  res.end('end', onWriteAfterEndError);
181cb0ef41Sopenharmony_ci  assert.strictEqual(res.writableCorked, 0);
191cb0ef41Sopenharmony_ci  res.on('error', onWriteAfterEndError);
201cb0ef41Sopenharmony_ci  res.on('finish', common.mustCall(() => {
211cb0ef41Sopenharmony_ci    res.end(common.mustCall((err) => {
221cb0ef41Sopenharmony_ci      assert.strictEqual(err.code, 'ERR_STREAM_ALREADY_FINISHED');
231cb0ef41Sopenharmony_ci      server.close();
241cb0ef41Sopenharmony_ci    }));
251cb0ef41Sopenharmony_ci  }));
261cb0ef41Sopenharmony_ci}));
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ciserver.listen(0);
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ciserver.on('listening', common.mustCall(function() {
311cb0ef41Sopenharmony_ci  http
321cb0ef41Sopenharmony_ci    .request({
331cb0ef41Sopenharmony_ci      port: server.address().port,
341cb0ef41Sopenharmony_ci      method: 'GET',
351cb0ef41Sopenharmony_ci      path: '/'
361cb0ef41Sopenharmony_ci    })
371cb0ef41Sopenharmony_ci    .end();
381cb0ef41Sopenharmony_ci}));
39