From d77f75774516fc9dfefe6c6523a94960df5100b5 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 16 Jun 2009 20:53:15 +0200 Subject: [PATCH] Fix test-http-client-race bug --- src/http.js | 9 +++++++-- test/test-http-client-race.js | 13 ++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/http.js b/src/http.js index 6d5b2eda2f..ccbb994fe4 100644 --- a/src/http.js +++ b/src/http.js @@ -385,7 +385,12 @@ node.http.Client = function (port, host) { connection.connect(port, host); return; } - while (this === requests[0] && output.length > 0) { + //node.debug("HTTP CLIENT flush. readyState = " + connection.readyState); + while ( this === requests[0] + && output.length > 0 + && connection.readyState == "open" + ) + { var out = output.shift(); connection.send(out[0], out[1]); } @@ -403,7 +408,7 @@ node.http.Client = function (port, host) { connection.onConnect = function () { //node.debug("HTTP CLIENT onConnect. readyState = " + connection.readyState); - //node.debug("requests[0].uri = " + requests[0].uri); + //node.debug("requests[0].uri = '" + requests[0].uri + "'"); requests[0].flush(); }; diff --git a/test/test-http-client-race.js b/test/test-http-client-race.js index 32b95d614d..7761d4960d 100644 --- a/test/test-http-client-race.js +++ b/test/test-http-client-race.js @@ -3,7 +3,10 @@ PORT = 8888; var server = new node.http.Server(function (req, res) { res.sendHeader(200, [["content-type", "text/plain"]]); - res.sendBody("hello world\n"); + if (req.uri.path == "/1") + res.sendBody("hello world 1\n"); + else + res.sendBody("hello world 2\n"); res.finish(); }) server.listen(PORT); @@ -13,13 +16,13 @@ var client = new node.http.Client(PORT); var body1 = ""; var body2 = ""; -client.get("/").finish(function (res1) { +client.get("/1").finish(function (res1) { res1.setBodyEncoding("utf8"); res1.onBody = function (chunk) { body1 += chunk; }; res1.onBodyComplete = function () { - client.get("/").finish(function (res2) { + client.get("/2").finish(function (res2) { res2.setBodyEncoding("utf8"); res2.onBody = function (chunk) { body2 += chunk; }; res2.onBodyComplete = function () { @@ -30,6 +33,6 @@ client.get("/").finish(function (res1) { }); function onExit () { - assertEqual("hello world\n", body1); - assertEqual("hello world\n", body2); + assertEquals("hello world 1\n", body1); + assertEquals("hello world 2\n", body2); }