Skip to content
Permalink
Browse files

[test] Add a basic test for reconnecting

  • Loading branch information...
mmalecki committed Mar 24, 2013
1 parent fb2f774 commit 8889640721430dd314914dcaae19bac6ba0cf2ed
Showing with 72 additions and 0 deletions.
  1. +72 −0 test/net/client-reconnect-test.js
@@ -0,0 +1,72 @@
/*
* client-reconnect-test.js: Basic tests for the reconnection of net client.
*
* (C) 2013, Nodejitsu Inc.
*
*/

var assert = require('assert'),
vows = require('vows'),
async = require('utile').async,
godot = require('../../lib/godot'),
helpers = require('../helpers'),
macros = require('../macros');

vows.describe('godot/net/client').addBatch({
"Godot client": {
"with no backoff and no server": {
topic: function () {
var callback = this.callback,
port = helpers.nextPort;

var client = godot.createClient({
type: 'tcp',
producers: [
godot.producer(helpers.fixtures['producer-test'])
]
});

client.connect(port);
client.on('error', function (err) {
callback(null, err);
});
},
"should emit an error": function (_, err) {
assert(err);
assert.instanceOf(err, Error);
}
},
"with backoff and no server": {
topic: function () {
var callback = this.callback,
port = helpers.nextPort,
d = new Date();

var client = godot.createClient({
type: 'tcp',
producers: [
godot.producer(helpers.fixtures['producer-test'])
],
reconnect: {
type: 'exponential',
maxTries: 2,
initialDelay: 100,
maxDelay: 300
}
});

client.connect(port);
client.on('error', function (err) {
callback(null, err, (new Date() - d));
});
},
"should emit an error": function (_, err) {
assert(err);
assert.instanceOf(err, Error);
},
"should take appropiate amount of time": function (_, err, t) {
assert(t >= 300);
}
}
}
}).export(module);

0 comments on commit 8889640

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.