Permalink
Browse files

added tests for callbacks and buffering

  • Loading branch information...
1 parent 88071ee commit 28af6bd7773839dd51913116ee6650978c767d15 @albertyfwu albertyfwu committed Mar 17, 2013
Showing with 86 additions and 0 deletions.
  1. +86 −0 test/server.js
View
@@ -803,7 +803,93 @@ 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 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) {
+ i++;
+ });
+ });
+
+ socket.on('open', function () {
+ socket.send('a', function () {
+ j++
+ });
+ });
+
+ setTimeout(function() {
+ expect(i).to.be(j);
+ done();
+ }, 10);
+ });
+ });
+
+ it('should execute 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) {
+ i++;
+ });
+ });
+
+ socket.on('open', function () {
+ socket.send('a', function () {
+ j++
+ });
+ });
+
+ setTimeout(function() {
+ expect(i).to.be(j);
+ done();
+ }, 10);
+ });
+ });
+
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 28af6bd

Please sign in to comment.