Permalink
Browse files

[test] Add test for the ability to trigger a client-side reconnection…

… from the server
  • Loading branch information...
1 parent b03f2d8 commit cd6d30f1fca9162f5a77ce5040319e967cb1ba36 @lpinca lpinca committed Feb 14, 2014
Showing with 31 additions and 1 deletion.
  1. +31 −1 test/transformer.base.js
View
@@ -361,7 +361,7 @@ module.exports = function base(transformer) {
});
});
- it('should reconnect when the connection closes unexcpectingly', function (done) {
+ it('should reconnect when the connection closes unexpectedly', function (done) {
primus.on('connection', function (spark) {
if (!reconnected) {
reconnected = true;
@@ -402,6 +402,36 @@ module.exports = function base(transformer) {
});
});
+ it('should allow to trigger a client-side reconnect from server', function (done) {
+ primus.on('connection', function (spark) {
+ if (!reconnected) {
+ reconnected = true;
+ spark.end(null, { reconnect: true });
+ }
+ });
+
+ var socket = new Socket('http://localhost:'+ server.portnumber)
+ , reconnected = false
+ , reconnect = false
+ , opened = 0;
+
+ socket.on('reconnect', function (message) {
+ reconnect = true;
+ });
+
+ socket.on('open', function () {
+ if (++opened !== 2) return;
+
+ expect(reconnect).to.equal(true);
+
+ primus.forEach(function (socket) {
+ socket.end();
+ });
+
+ done();
+ });
+ });
+
it('should not increment the attempt if a backoff is running', function (done) {
var socket = new Socket('http://localhost:'+ server.portnumber);

0 comments on commit cd6d30f

Please sign in to comment.