node/test/parallel/test-http-pause-resume-one-end.js
Rich Trott 6f02957846 test: refactor test-http-pause-resume-one-end
* setTimeout() with no duration -> setImmediate()
* var -> const
* remove unused variable `chunk`

PR-URL: https://github.com/nodejs/node/pull/10210
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2016-12-13 16:30:30 -08:00

28 lines
625 B
JavaScript

'use strict';
const common = require('../common');
const http = require('http');
const server = http.Server(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
server.close();
});
server.listen(0, common.mustCall(function() {
const opts = {
port: this.address().port,
headers: { connection: 'close' }
};
http.get(opts, common.mustCall(function(res) {
res.on('data', common.mustCall(function() {
res.pause();
setImmediate(function() {
res.resume();
});
}));
res.on('end', common.mustCall(function() {}));
}));
}));