Skip to content

Instantly share code, notes, and snippets.

@jameshartig
Created December 2, 2011 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jameshartig/1422141 to your computer and use it in GitHub Desktop.
Save jameshartig/1422141 to your computer and use it in GitHub Desktop.
Test case for failing setTimeout(0)
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