test: fix test-http-dump-req-when-res-ends
Fix test-http-dump-req-when-res-ends and move it back to test/parallel/ PR-URL: https://github.com/nodejs/node/pull/19866 Refs: https://github.com/nodejs/node/pull/19823 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
2852521c49
commit
96e82beac3
@ -1,25 +1,24 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const common = require('../common');
|
const { mustCall } = require('../common');
|
||||||
const http = require('http');
|
|
||||||
const assert = require('assert');
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const http = require('http');
|
||||||
|
const { strictEqual } = require('assert');
|
||||||
|
|
||||||
let resEnd = null;
|
const server = http.createServer(mustCall(function(req, res) {
|
||||||
|
strictEqual(req.socket.listenerCount('data'), 1);
|
||||||
const server = http.createServer(common.mustCall(function(req, res) {
|
req.socket.once('data', mustCall(function() {
|
||||||
|
// Ensure that a chunk of data is received before calling `res.end()`.
|
||||||
|
res.end('hello world');
|
||||||
|
}));
|
||||||
// This checks if the request gets dumped
|
// This checks if the request gets dumped
|
||||||
// resume will be triggered by res.end().
|
// resume will be triggered by res.end().
|
||||||
req.on('resume', common.mustCall(function() {
|
req.on('resume', mustCall(function() {
|
||||||
// There is no 'data' event handler anymore
|
// There is no 'data' event handler anymore
|
||||||
// it gets automatically removed when dumping the request.
|
// it gets automatically removed when dumping the request.
|
||||||
assert.strictEqual(req.listenerCount('data'), 0);
|
strictEqual(req.listenerCount('data'), 0);
|
||||||
|
req.on('data', mustCall());
|
||||||
req.on('data', common.mustCallAtLeast(function(d) {
|
|
||||||
// Leaving the console.log explicitly, so that
|
|
||||||
// we can know how many chunks we have received.
|
|
||||||
console.log('data', d);
|
|
||||||
}, 1));
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// We explicitly pause the stream
|
// We explicitly pause the stream
|
||||||
@ -30,15 +29,9 @@ const server = http.createServer(common.mustCall(function(req, res) {
|
|||||||
|
|
||||||
// Start sending the response.
|
// Start sending the response.
|
||||||
res.flushHeaders();
|
res.flushHeaders();
|
||||||
|
|
||||||
resEnd = function() {
|
|
||||||
setImmediate(function() {
|
|
||||||
res.end('hello world');
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
server.listen(0, common.mustCall(function() {
|
server.listen(0, mustCall(function() {
|
||||||
const req = http.request({
|
const req = http.request({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
port: server.address().port
|
port: server.address().port
|
||||||
@ -48,13 +41,10 @@ server.listen(0, common.mustCall(function() {
|
|||||||
// for the body.
|
// for the body.
|
||||||
req.flushHeaders();
|
req.flushHeaders();
|
||||||
|
|
||||||
req.on('response', common.mustCall(function(res) {
|
req.on('response', mustCall(function(res) {
|
||||||
// Pipe the body as soon as we get the headers of the
|
// Pipe the body as soon as we get the headers of the
|
||||||
// response back.
|
// response back.
|
||||||
const readFileStream = fs.createReadStream(__filename);
|
fs.createReadStream(__filename).pipe(req);
|
||||||
readFileStream.on('end', resEnd);
|
|
||||||
|
|
||||||
readFileStream.pipe(req);
|
|
||||||
|
|
||||||
res.resume();
|
res.resume();
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user