forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix: HTTP client automatically reconnecting
Test case by tlynn.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
process.mixin(require("./common")); | ||
|
||
var tcp = require("tcp"), | ||
sys = require("sys"), | ||
http = require("http"); | ||
|
||
var PORT = 2143; | ||
|
||
var errorCount = 0; | ||
var eofCount = 0; | ||
|
||
var server = tcp.createServer(function(socket) { | ||
socket.close(); | ||
}); | ||
server.listen(PORT); | ||
|
||
var client = http.createClient(PORT); | ||
|
||
client.addListener("error", function() { | ||
sys.puts("ERROR!"); | ||
errorCount++; | ||
}); | ||
|
||
client.addListener("eof", function() { | ||
sys.puts("EOF!"); | ||
eofCount++; | ||
}); | ||
|
||
var request = client.request("GET", "/", {"host": "localhost"}); | ||
request.finish(function(response) { | ||
sys.puts("STATUS: " + response.statusCode); | ||
}); | ||
|
||
setTimeout(function () { | ||
server.close(); | ||
}, 500); | ||
|
||
|
||
process.addListener('exit', function () { | ||
assert.equal(0, errorCount); | ||
assert.equal(1, eofCount); | ||
}); |