summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRobert Nagy <ronagy@icloud.com>2018-04-23 14:42:19 -0200
committerTrivikram Kamat <16024985+trivikr@users.noreply.github.com>2018-05-13 22:54:34 -0700
commitffb503be5f07a26d73a2b3b59955636452948ba7 (patch)
treed81dca8a0e19a4a1a277607007aa3ea140fbe825 /test
parentfcf2e4207edab9b85f8435b89489dd6148a7637e (diff)
downloadandroid-node-v8-ffb503be5f07a26d73a2b3b59955636452948ba7.tar.gz
android-node-v8-ffb503be5f07a26d73a2b3b59955636452948ba7.tar.bz2
android-node-v8-ffb503be5f07a26d73a2b3b59955636452948ba7.zip
http: fix client response close & aborted
Fixes: https://github.com/nodejs/node/issues/20102 Fixes: https://github.com/nodejs/node/issues/20101 Fixes: https://github.com/nodejs/node/issues/1735 - Response should always emit close. - Response should always emit aborted if aborted. - Response should always emit close after request has emitted close. PR-URL: https://github.com/nodejs/node/pull/20075 Fixes: https://github.com/nodejs/node/issues/17352 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-http-response-close.js71
1 files changed, 46 insertions, 25 deletions
diff --git a/test/parallel/test-http-response-close.js b/test/parallel/test-http-response-close.js
index c58a5884d5..4c36003357 100644
--- a/test/parallel/test-http-response-close.js
+++ b/test/parallel/test-http-response-close.js
@@ -23,29 +23,50 @@
const common = require('../common');
const http = require('http');
-const server = http.createServer(common.mustCall(function(req, res) {
- res.writeHead(200);
- res.write('a');
+{
+ const server = http.createServer(
+ common.mustCall((req, res) => {
+ res.writeHead(200);
+ res.write('a');
+ })
+ );
+ server.listen(
+ 0,
+ common.mustCall(() => {
+ http.get(
+ { port: server.address().port },
+ common.mustCall((res) => {
+ res.on('data', common.mustCall(() => {
+ res.destroy();
+ }));
+ res.on('close', common.mustCall(() => {
+ server.close();
+ }));
+ })
+ );
+ })
+ );
+}
- req.on('close', common.mustCall(function() {
- console.error('request aborted');
- }));
- res.on('close', common.mustCall(function() {
- console.error('response aborted');
- }));
-}));
-server.listen(0);
-
-server.on('listening', function() {
- console.error('make req');
- http.get({
- port: this.address().port
- }, function(res) {
- console.error('got res');
- res.on('data', function(data) {
- console.error('destroy res');
- res.destroy();
- server.close();
- });
- });
-});
+{
+ const server = http.createServer(
+ common.mustCall((req, res) => {
+ res.writeHead(200);
+ res.end('a');
+ })
+ );
+ server.listen(
+ 0,
+ common.mustCall(() => {
+ http.get(
+ { port: server.address().port },
+ common.mustCall((res) => {
+ res.on('close', common.mustCall(() => {
+ server.close();
+ }));
+ res.resume();
+ })
+ );
+ })
+ );
+}