Created
December 2, 2011 07:03
-
-
Save jameshartig/1422141 to your computer and use it in GitHub Desktop.
Test case for failing setTimeout(0)
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
var net = require("net"), | |
sys = require('util'), | |
socket = new net.connect(80, '74.125.115.99'); //google.com | |
socket.timedOut = false; | |
socket.setTimeout(1000, function() { | |
console.log("setTimeout(0) failed. Timed out!"); | |
socket.timedOut = true; | |
}); | |
socket.setTimeout(0); | |
setTimeout(function() { | |
socket.destroy(); | |
if (!socket.timedOut) { | |
console.log("setTimeout(0) worked correctly."); | |
} | |
//repeat with attempt to fix | |
var socket2 = new net.connect(80, '74.125.115.99'); //google.com | |
socket2.timedOut = false; | |
socket2.setTimeout(1000, function() { | |
console.log("setTimeout(0) failed 2nd time. Timed out!"); | |
socket2.timedOut = true; | |
}); | |
socket2.setTimeout(0); | |
socket2.removeAllListeners('timeout'); | |
setTimeout(function() { | |
socket2.destroy(); | |
if (!socket2.timedOut) { | |
console.log("setTimeout(0) worked correctly 2nd time."); | |
} | |
}, 2000); | |
}, 2000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment