Skip to content

Commit

Permalink
[test] Add a basic test for reconnecting
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalecki committed Mar 24, 2013
1 parent fb2f774 commit 8889640
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions 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.