From 39da31bb5a1fec92c6ab43a86107ca474e6ee239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Thu, 4 Aug 2016 14:41:33 +0200 Subject: [PATCH] test: fix "socket hang up" error in app.test Rework the test to always wait for the client request to finish before calling the test done. --- test/app.test.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/app.test.js b/test/app.test.js index 9df0d1cd..0afb23c2 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -1037,8 +1037,18 @@ describe('app', function() { }); function executeMiddlewareHandlers(app, urlPath, callback) { + var handlerError = undefined; var server = http.createServer(function(req, res) { - app.handle(req, res, callback); + app.handle(req, res, function(err) { + if (err) { + handlerError = err; + res.statusCode = err.status || err.statusCode || 500; + res.end(err.stack || err); + } else { + res.statusCode = 204; + res.end(); + } + }); }); if (callback === undefined && typeof urlPath === 'function') { @@ -1049,6 +1059,6 @@ function executeMiddlewareHandlers(app, urlPath, callback) { request(server) .get(urlPath) .end(function(err) { - if (err) return callback(err); + callback(handlerError || err); }); }