Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[test] Add a test where server eventually comes up online

  • Loading branch information...
commit da1711b0e5cd245c59cb2a361448fdfd22e56837 1 parent 8889640
@mmalecki mmalecki authored
Showing with 46 additions and 1 deletion.
  1. +46 −1 test/net/client-reconnect-test.js
View
47 test/net/client-reconnect-test.js
@@ -10,7 +10,8 @@ var assert = require('assert'),
async = require('utile').async,
godot = require('../../lib/godot'),
helpers = require('../helpers'),
- macros = require('../macros');
+ macros = require('../macros'),
+ mocks = require('../mocks');
vows.describe('godot/net/client').addBatch({
"Godot client": {
@@ -67,6 +68,50 @@ vows.describe('godot/net/client').addBatch({
"should take appropiate amount of time": function (_, err, t) {
assert(t >= 300);
}
+ },
+ "with backoff and server eventually coming up": {
+ 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) {
+ throw err;
+ });
+
+ setTimeout(function () {
+ mocks.net.createServer({ type: 'tcp', port: port }, function (err, server) {
+ if (err) {
+ throw err;
+ }
+
+ server.once('data', function (data) {
+ callback(null, data, (new Date()) - d);
+ });
+ });
+ }, 100);
+ },
+ "should send data": function (err, data) {
+ assert(!err);
+ assert(data);
+ },
+ "should take appropiate amount of time": function (_, err, t) {
+ assert(t >= 200);
+ }
}
}
}).export(module);
Please sign in to comment.
Something went wrong with that request. Please try again.