mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
test: deflake test-http-remove-header-stays-removed
Instead of relying on a timer, verify that `socket.end()` is called when the `'finish'` event is emitted on the `ServerResponse` object. PR-URL: https://github.com/nodejs/node/pull/55004 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
This commit is contained in:
parent
afe56aa58b
commit
9bb6a1a790
@ -25,7 +25,9 @@ const assert = require('assert');
|
||||
|
||||
const http = require('http');
|
||||
|
||||
const server = http.createServer(function(request, response) {
|
||||
const server = http.createServer(common.mustCall(function(request, response) {
|
||||
const socket = response.socket;
|
||||
|
||||
// Removed headers should stay removed, even if node automatically adds them
|
||||
// to the output:
|
||||
response.removeHeader('connection');
|
||||
@ -36,32 +38,29 @@ const server = http.createServer(function(request, response) {
|
||||
response.removeHeader('date');
|
||||
response.setHeader('date', 'coffee o clock');
|
||||
|
||||
response.on('finish', common.mustCall(function() {
|
||||
// The socket should be closed immediately, with no keep-alive, because
|
||||
// no content-length or transfer-encoding are used.
|
||||
assert.strictEqual(socket.writableEnded, true);
|
||||
}));
|
||||
|
||||
response.end('beep boop\n');
|
||||
});
|
||||
|
||||
let response = '';
|
||||
|
||||
process.on('exit', function() {
|
||||
assert.strictEqual(response, 'beep boop\n');
|
||||
console.log('ok');
|
||||
});
|
||||
}));
|
||||
|
||||
server.listen(0, function() {
|
||||
http.get({ port: this.address().port }, function(res) {
|
||||
assert.strictEqual(res.statusCode, 200);
|
||||
assert.deepStrictEqual(res.headers, { date: 'coffee o clock' });
|
||||
|
||||
let response = '';
|
||||
res.setEncoding('ascii');
|
||||
res.on('data', function(chunk) {
|
||||
response += chunk;
|
||||
if (response === 'beep boop\n') {
|
||||
setTimeout(function() {
|
||||
// The socket should be closed immediately, with no keep-alive, because
|
||||
// no content-length or transfer-encoding are used:
|
||||
assert.strictEqual(res.socket.closed, true);
|
||||
server.close();
|
||||
}, common.platformTimeout(15));
|
||||
}
|
||||
});
|
||||
|
||||
res.on('end', function() {
|
||||
assert.strictEqual(response, 'beep boop\n');
|
||||
server.close();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user