2019-07-14 22:11:06 +02:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const http = require('http');
|
|
|
|
|
2021-03-29 11:20:57 +02:00
|
|
|
const onWriteAfterEndError = common.mustCall((err) => {
|
|
|
|
assert.strictEqual(err.code, 'ERR_STREAM_WRITE_AFTER_END');
|
|
|
|
}, 2);
|
|
|
|
|
2019-07-14 22:11:06 +02:00
|
|
|
const server = http.createServer(common.mustCall(function(req, res) {
|
|
|
|
res.end('testing ended state', common.mustCall());
|
2020-12-26 11:11:21 +01:00
|
|
|
assert.strictEqual(res.writableCorked, 0);
|
2020-10-28 15:14:48 +08:00
|
|
|
res.end(common.mustCall((err) => {
|
2021-03-29 11:20:57 +02:00
|
|
|
assert.strictEqual(err.code, 'ERR_STREAM_ALREADY_FINISHED');
|
2021-01-06 17:59:39 +01:00
|
|
|
}));
|
2021-03-29 11:20:57 +02:00
|
|
|
assert.strictEqual(res.writableCorked, 0);
|
|
|
|
res.end('end', onWriteAfterEndError);
|
|
|
|
assert.strictEqual(res.writableCorked, 0);
|
|
|
|
res.on('error', onWriteAfterEndError);
|
|
|
|
res.on('finish', common.mustCall(() => {
|
2019-07-14 22:11:06 +02:00
|
|
|
res.end(common.mustCall((err) => {
|
2021-03-29 11:20:57 +02:00
|
|
|
assert.strictEqual(err.code, 'ERR_STREAM_ALREADY_FINISHED');
|
2019-07-14 22:11:06 +02:00
|
|
|
server.close();
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
server.listen(0);
|
|
|
|
|
|
|
|
server.on('listening', common.mustCall(function() {
|
|
|
|
http
|
|
|
|
.request({
|
|
|
|
port: server.address().port,
|
|
|
|
method: 'GET',
|
|
|
|
path: '/'
|
|
|
|
})
|
|
|
|
.end();
|
|
|
|
}));
|