From 2eec008e0e3e018191029e93993d083af10f901b 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 d0f0aca6..fd2abfd8 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -1046,8 +1046,18 @@ describe('app', function() { }); function executeMiddlewareHandlers(app, urlPath, callback) { + var handlerError; 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') { @@ -1058,6 +1068,6 @@ function executeMiddlewareHandlers(app, urlPath, callback) { request(server) .get(urlPath) .end(function(err) { - if (err) return callback(err); + callback(handlerError || err); }); }