Permalink
Browse files

Merge branch 'master' of github.com:/LearnBoost/engine.io

  • Loading branch information...
2 parents ccb4b9c + db297a7 commit 17df993e760d56c9692d2a32106e021a3708836b @rauchg rauchg committed Mar 24, 2013
Showing with 201 additions and 3 deletions.
  1. +201 −3 test/server.js
View
@@ -226,11 +226,10 @@ describe('server', function () {
});
describe('close', function () {
- it('should be able to access non-empty writeBuffer at closing', function(done) {
- var opts = {allowUpgrades: false, pingInterval: 10, pingTimeout: 10 };
+ it('should be able to access non-empty writeBuffer at closing (server)', function(done) {
+ var opts = {allowUpgrades: false};
var engine = listen(opts, function (port) {
var socket = new eioc.Socket('http://localhost:%d'.s(port));
- socket.sendPacket = function (){};
engine.on('connection', function (conn) {
conn.on('close', function (reason) {
expect(conn.writeBuffer.length).to.be(1);
@@ -245,6 +244,27 @@ describe('server', function () {
});
});
+ it('should be able to access non-empty writeBuffer at closing (client)', function(done) {
+ var opts = {allowUpgrades: false};
+ var engine = listen(opts, function (port) {
+ var socket = new eioc.Socket('http://localhost:%d'.s(port));
+ socket.on('open', function() {
+ socket.on('close', function (reason) {
+ expect(socket.writeBuffer.length).to.be(1);
+ expect(socket.callbackBuffer.length).to.be(1);
+ setTimeout(function() {
+ expect(socket.writeBuffer.length).to.be(0);
+ expect(socket.callbackBuffer.length).to.be(0);
+ }, 10);
+ done();
+ });
+ socket.writeBuffer.push({ type: 'message', data: 'foo'});
+ socket.callbackBuffer.push(function() {});
+ socket.onError('');
+ });
+ });
+ });
+
it('should trigger on server if the client does not pong', function (done) {
var opts = { allowUpgrades: false, pingInterval: 5, pingTimeout: 5 };
var engine = listen(opts, function (port) {
@@ -803,7 +823,185 @@ describe('server', function () {
});
describe('send', function() {
+ describe('writeBuffer', function() {
+ it('should not empty until `drain` event (polling)', function (done) {
+ var engine = listen({ allowUpgrades: false }, function (port) {
+ var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['polling'] });
+ var totalEvents = 2;
+ socket.on('open', function() {
+ socket.send('a');
+ socket.send('b');
+ // writeBuffer should be nonempty, with 'a' still in it
+ expect(socket.writeBuffer.length).to.eql(2);
+ });
+ socket.transport.on('drain', function() {
+ expect(socket.writeBuffer.length).to.eql(--totalEvents);
+ totalEvents || done();
+ });
+ });
+ });
+
+ it('should not empty until `drain` event (websocket)', function (done) {
+ var engine = listen({ allowUpgrades: false }, function (port) {
+ var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['websocket'] });
+ var totalEvents = 2;
+ socket.on('open', function() {
+ socket.send('a');
+ socket.send('b');
+ // writeBuffer should be nonempty, with 'a' still in it
+ expect(socket.writeBuffer.length).to.eql(2);
+ });
+ socket.transport.on('drain', function() {
+ expect(socket.writeBuffer.length).to.eql(--totalEvents);
+ totalEvents || done();
+ });
+ });
+ });
+ });
+
describe('callback', function() {
+ it('should execute in order when message sent (client) (polling)', function (done) {
+ var engine = listen({ allowUpgrades: false }, function (port) {
+ var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['polling'] });
+ var i = 0;
+ var j = 0;
+
+ engine.on('connection', function(conn) {
+ conn.on('message', function(msg) {
+ conn.send(msg);
+ });
+ });
+
+ socket.on('open', function () {
+ socket.on('message', function(msg) {
+ // send another packet until we've sent 3 total
+ if (++i < 3) {
+ expect(i).to.eql(j);
+ sendFn();
+ } else {
+ done();
+ }
+ });
+
+ function sendFn() {
+ socket.send(j, (function(value) {
+ j++;
+ })(j));
+ }
+
+ sendFn();
+ });
+ });
+ });
+
+ it('should execute in order when message sent (client) (websocket)', function (done) {
+ var engine = listen({ allowUpgrades: false }, function (port) {
+ var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['websocket'] });
+ var i = 0;
+ var j = 0;
+
+ engine.on('connection', function(conn) {
+ conn.on('message', function(msg) {
+ conn.send(msg);
+ });
+ });
+
+ socket.on('open', function () {
+ socket.on('message', function(msg) {
+ // send another packet until we've sent 3 total
+ if (++i < 3) {
+ expect(i).to.eql(j);
+ sendFn();
+ } else {
+ done();
+ }
+ });
+
+ function sendFn() {
+ socket.send(j, (function(value) {
+ j++;
+ })(j));
+ }
+
+ sendFn();
+ });
+ });
+ });
+
+ it('should execute in order with payloads (client) (polling)', function (done) {
+ var engine = listen({ allowUpgrades: false }, function (port) {
+ var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['polling'] });
+ var i = 0;
+ var lastCbFired = 0;
+
+ engine.on('connection', function(conn) {
+ conn.on('message', function(msg) {
+ conn.send(msg);
+ });
+ });
+
+ socket.on('open', function () {
+ socket.on('message', function(msg) {
+ expect(msg).to.eql(i + 1);
+ i++;
+ });
+
+ function cb(value) {
+ expect(value).to.eql(lastCbFired + 1);
+ lastCbFired = value;
+ if (value == 3) {
+ done();
+ }
+ }
+
+ // 2 and 3 will be in the same payload
+ socket.once('flush', function() {
+ socket.send(2, function() { cb(2); });
+ socket.send(3, function() { cb(3); });
+ });
+
+ socket.send(1, function() { cb(1); });
+ });
+ });
+ });
+
+ it('should execute in order with payloads (client) (websocket)', function (done) {
+ var engine = listen({ allowUpgrades: false }, function (port) {
+ var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['websocket'] });
+ var i = 0;
+ var lastCbFired = 0;
+
+ engine.on('connection', function(conn) {
+ conn.on('message', function(msg) {
+ conn.send(msg);
+ });
+ });
+
+ socket.on('open', function () {
+ socket.on('message', function(msg) {
+ expect(msg).to.eql(i + 1);
+ i++;
+ });
+
+ function cb(value) {
+ expect(value).to.eql(lastCbFired + 1);
+ lastCbFired = value;
+ if (value == 3) {
+ done();
+ }
+ }
+
+ // 2 and 3 will be in the same payload
+ socket.once('flush', function() {
+ socket.send(2, function() { cb(2); });
+ socket.send(3, function() { cb(3); });
+ });
+
+ socket.send(1, function() { cb(1); });
+ });
+ });
+ });
+
it('should execute when message sent (polling)', function (done) {
var engine = listen({ allowUpgrades: false }, function (port) {
var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['polling'] });

0 comments on commit 17df993

Please sign in to comment.