Permalink
Browse files

Add timeout test

  • Loading branch information...
1 parent 37a9088 commit 7c7722744ed45ac4250ed70088fbc005936b1dea @pfleidi committed May 28, 2011
Showing with 28 additions and 0 deletions.
  1. +28 −0 test/wwwdude-networkerrors.js
View
28 test/wwwdude-networkerrors.js
@@ -32,10 +32,38 @@ exports.networkConnRefused = function (beforeExit) {
_testClientErrs(beforeExit, 'ECONNREFUSED', 'http://localhost:63424');
};
+/*
exports.networkHostNotReachable = function (beforeExit) {
_testClientErrs(beforeExit, 'ETIMEDOUT', 'http://127.0.22.32:63424');
};
+*/
exports.networkDomainNotFound = function (beforeExit) {
_testClientErrs(beforeExit, 'ENOTFOUND', 'http://wrong.tld.foo.bar:63424');
};
+
+exports.timeoutTest = function (beforeExit) {
+ var callbacks = 0;
+ var client = HttpClient.createClient({
+ timeout: 500
+ });
+ var start = new Date();
+
+ client.get('http://127.0.22.32:63424')
+ .on('error', function (err) {
+ var elapsed = new Date() - start;
+ callbacks += 1;
+ console.log(elapsed);
+ assert.ok(err);
+ assert.ok();
+ })
+ .on('complete', function () {
+ callbacks += 1;
+ throw new Error('This should not happen');
+ });
+
+
+ beforeExit(function () {
+ assert.strictEqual(callbacks, 1, 'Ensure all callbacks are called');
+ });
+};

0 comments on commit 7c77227

Please sign in to comment.