Skip to content
This repository
Browse code

added tests for callbacks and buffering

  • Loading branch information...
commit 28af6bd7773839dd51913116ee6650978c767d15 1 parent 88071ee
albertyfwu authored

Showing 1 changed file with 86 additions and 0 deletions. Show diff stats Hide diff stats

  1. 86  test/server.js
86  test/server.js
@@ -803,7 +803,93 @@ describe('server', function () {
803 803
   });
804 804
 
805 805
   describe('send', function() {
  806
+    describe('writeBuffer', function() {
  807
+      it('should not empty until `drain` event (polling)', function (done) {
  808
+        var engine = listen({ allowUpgrades: false }, function (port) {
  809
+          var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['polling'] });
  810
+          var totalEvents = 2;
  811
+          socket.on('open', function() {
  812
+            socket.send('a');
  813
+            socket.send('b');
  814
+            // writeBuffer should be nonempty, with 'a' still in it
  815
+            expect(socket.writeBuffer.length).to.eql(2);
  816
+          });
  817
+          socket.transport.on('drain', function() {
  818
+            expect(socket.writeBuffer.length).to.eql(--totalEvents);
  819
+            totalEvents || done();
  820
+          });
  821
+        });
  822
+      });
  823
+
  824
+      it('should not empty until `drain` event (websocket)', function (done) {
  825
+        var engine = listen({ allowUpgrades: false }, function (port) {
  826
+          var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['websocket'] });
  827
+          var totalEvents = 2;
  828
+          socket.on('open', function() {
  829
+            socket.send('a');
  830
+            socket.send('b');
  831
+            // writeBuffer should be nonempty, with 'a' still in it
  832
+            expect(socket.writeBuffer.length).to.eql(2);
  833
+          });
  834
+          socket.transport.on('drain', function() {
  835
+            expect(socket.writeBuffer.length).to.eql(--totalEvents);
  836
+            totalEvents || done();
  837
+          });
  838
+        });
  839
+      });
  840
+    });
  841
+
806 842
     describe('callback', function() {
  843
+      it('should execute when message sent (client) (polling)', function (done) {
  844
+        var engine = listen({ allowUpgrades: false }, function (port) {
  845
+          var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['polling'] });
  846
+          var i = 0;
  847
+          var j = 0;
  848
+
  849
+          engine.on('connection', function(conn) {
  850
+            conn.on('message', function (msg) {
  851
+              i++;
  852
+            });
  853
+          });
  854
+
  855
+          socket.on('open', function () {
  856
+            socket.send('a', function () {
  857
+              j++
  858
+            });
  859
+          });
  860
+
  861
+          setTimeout(function() {
  862
+            expect(i).to.be(j);
  863
+            done();
  864
+          }, 10);
  865
+        });
  866
+      });
  867
+
  868
+      it('should execute when message sent (client) (websocket)', function (done) {
  869
+        var engine = listen({ allowUpgrades: false }, function (port) {
  870
+          var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['websocket'] });
  871
+          var i = 0;
  872
+          var j = 0;
  873
+
  874
+          engine.on('connection', function(conn) {
  875
+            conn.on('message', function (msg) {
  876
+              i++;
  877
+            });
  878
+          });
  879
+
  880
+          socket.on('open', function () {
  881
+            socket.send('a', function () {
  882
+              j++
  883
+            });
  884
+          });
  885
+
  886
+          setTimeout(function() {
  887
+            expect(i).to.be(j);
  888
+            done();
  889
+          }, 10);
  890
+        });
  891
+      });
  892
+
807 893
       it('should execute when message sent (polling)', function (done) {
808 894
         var engine = listen({ allowUpgrades: false }, function (port) {
809 895
           var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['polling'] });

0 notes on commit 28af6bd

Please sign in to comment.
Something went wrong with that request. Please try again.