Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 17df993e760d56c9692d2a32106e021a3708836b 2 parents ccb4b9c + db297a7
Guillermo Rauch authored March 23, 2013

Showing 1 changed file with 201 additions and 3 deletions. Show diff stats Hide diff stats

  1. 204  test/server.js
204  test/server.js
@@ -226,11 +226,10 @@ describe('server', function () {
226 226
   });
227 227
 
228 228
   describe('close', function () {
229  
-    it('should be able to access non-empty writeBuffer at closing', function(done) {
230  
-      var opts = {allowUpgrades: false, pingInterval: 10, pingTimeout: 10 };
  229
+    it('should be able to access non-empty writeBuffer at closing (server)', function(done) {
  230
+      var opts = {allowUpgrades: false};
231 231
       var engine = listen(opts, function (port) {
232 232
         var socket = new eioc.Socket('http://localhost:%d'.s(port));
233  
-        socket.sendPacket = function (){};
234 233
         engine.on('connection', function (conn) {
235 234
           conn.on('close', function (reason) {
236 235
             expect(conn.writeBuffer.length).to.be(1);
@@ -245,6 +244,27 @@ describe('server', function () {
245 244
       });
246 245
     });
247 246
 
  247
+    it('should be able to access non-empty writeBuffer at closing (client)', function(done) {
  248
+      var opts = {allowUpgrades: false};
  249
+      var engine = listen(opts, function (port) {
  250
+        var socket = new eioc.Socket('http://localhost:%d'.s(port));
  251
+        socket.on('open', function() {          
  252
+          socket.on('close', function (reason) {
  253
+            expect(socket.writeBuffer.length).to.be(1);
  254
+            expect(socket.callbackBuffer.length).to.be(1);
  255
+            setTimeout(function() {
  256
+              expect(socket.writeBuffer.length).to.be(0);
  257
+              expect(socket.callbackBuffer.length).to.be(0);
  258
+            }, 10);
  259
+            done();
  260
+          });
  261
+          socket.writeBuffer.push({ type: 'message', data: 'foo'});
  262
+          socket.callbackBuffer.push(function() {});
  263
+          socket.onError('');
  264
+        });
  265
+      });
  266
+    });
  267
+
248 268
     it('should trigger on server if the client does not pong', function (done) {
249 269
       var opts = { allowUpgrades: false, pingInterval: 5, pingTimeout: 5 };
250 270
       var engine = listen(opts, function (port) {
@@ -803,7 +823,185 @@ describe('server', function () {
803 823
   });
804 824
 
805 825
   describe('send', function() {
  826
+    describe('writeBuffer', function() {
  827
+      it('should not empty until `drain` event (polling)', function (done) {
  828
+        var engine = listen({ allowUpgrades: false }, function (port) {
  829
+          var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['polling'] });
  830
+          var totalEvents = 2;
  831
+          socket.on('open', function() {
  832
+            socket.send('a');
  833
+            socket.send('b');
  834
+            // writeBuffer should be nonempty, with 'a' still in it
  835
+            expect(socket.writeBuffer.length).to.eql(2);
  836
+          });
  837
+          socket.transport.on('drain', function() {
  838
+            expect(socket.writeBuffer.length).to.eql(--totalEvents);
  839
+            totalEvents || done();
  840
+          });
  841
+        });
  842
+      });
  843
+
  844
+      it('should not empty until `drain` event (websocket)', function (done) {
  845
+        var engine = listen({ allowUpgrades: false }, function (port) {
  846
+          var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['websocket'] });
  847
+          var totalEvents = 2;
  848
+          socket.on('open', function() {
  849
+            socket.send('a');
  850
+            socket.send('b');
  851
+            // writeBuffer should be nonempty, with 'a' still in it
  852
+            expect(socket.writeBuffer.length).to.eql(2);
  853
+          });
  854
+          socket.transport.on('drain', function() {
  855
+            expect(socket.writeBuffer.length).to.eql(--totalEvents);
  856
+            totalEvents || done();
  857
+          });
  858
+        });
  859
+      });
  860
+    });
  861
+
806 862
     describe('callback', function() {
  863
+      it('should execute in order when message sent (client) (polling)', function (done) {
  864
+        var engine = listen({ allowUpgrades: false }, function (port) {
  865
+          var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['polling'] });
  866
+          var i = 0;
  867
+          var j = 0;
  868
+
  869
+          engine.on('connection', function(conn) {
  870
+            conn.on('message', function(msg) {
  871
+              conn.send(msg);
  872
+            });
  873
+          });
  874
+
  875
+          socket.on('open', function () {
  876
+            socket.on('message', function(msg) {
  877
+              // send another packet until we've sent 3 total
  878
+              if (++i < 3) {
  879
+                expect(i).to.eql(j);
  880
+                sendFn();
  881
+              } else {
  882
+                done();
  883
+              }
  884
+            });
  885
+
  886
+            function sendFn() {
  887
+              socket.send(j, (function(value) {
  888
+                j++;
  889
+              })(j));
  890
+            }
  891
+
  892
+            sendFn();
  893
+          });
  894
+        });
  895
+      });
  896
+
  897
+      it('should execute in order when message sent (client) (websocket)', function (done) {
  898
+        var engine = listen({ allowUpgrades: false }, function (port) {
  899
+          var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['websocket'] });
  900
+          var i = 0;
  901
+          var j = 0;
  902
+
  903
+          engine.on('connection', function(conn) {
  904
+            conn.on('message', function(msg) {
  905
+              conn.send(msg);
  906
+            });
  907
+          });
  908
+
  909
+          socket.on('open', function () {
  910
+            socket.on('message', function(msg) {
  911
+              // send another packet until we've sent 3 total
  912
+              if (++i < 3) {
  913
+                expect(i).to.eql(j);
  914
+                sendFn();
  915
+              } else {
  916
+                done();
  917
+              }
  918
+            });
  919
+
  920
+            function sendFn() {
  921
+              socket.send(j, (function(value) {
  922
+                j++;
  923
+              })(j));
  924
+            }
  925
+
  926
+            sendFn();
  927
+          });
  928
+        });
  929
+      });
  930
+
  931
+      it('should execute in order with payloads (client) (polling)', function (done) {
  932
+        var engine = listen({ allowUpgrades: false }, function (port) {
  933
+          var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['polling'] });
  934
+          var i = 0;
  935
+          var lastCbFired = 0;
  936
+
  937
+          engine.on('connection', function(conn) {
  938
+            conn.on('message', function(msg) {
  939
+              conn.send(msg);
  940
+            });
  941
+          });
  942
+
  943
+          socket.on('open', function () {
  944
+            socket.on('message', function(msg) {
  945
+              expect(msg).to.eql(i + 1);
  946
+              i++;
  947
+            });
  948
+
  949
+            function cb(value) {
  950
+              expect(value).to.eql(lastCbFired + 1);
  951
+              lastCbFired = value;
  952
+              if (value == 3) {
  953
+                done();
  954
+              }
  955
+            }
  956
+
  957
+            // 2 and 3 will be in the same payload
  958
+            socket.once('flush', function() {
  959
+              socket.send(2, function() { cb(2); });
  960
+              socket.send(3, function() { cb(3); });
  961
+            });
  962
+
  963
+            socket.send(1, function() { cb(1); });
  964
+          });
  965
+        });
  966
+      });
  967
+
  968
+      it('should execute in order with payloads (client) (websocket)', function (done) {
  969
+        var engine = listen({ allowUpgrades: false }, function (port) {
  970
+          var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['websocket'] });
  971
+          var i = 0;
  972
+          var lastCbFired = 0;
  973
+
  974
+          engine.on('connection', function(conn) {
  975
+            conn.on('message', function(msg) {
  976
+              conn.send(msg);
  977
+            });
  978
+          });
  979
+
  980
+          socket.on('open', function () {
  981
+            socket.on('message', function(msg) {
  982
+              expect(msg).to.eql(i + 1);
  983
+              i++;
  984
+            });
  985
+
  986
+            function cb(value) {
  987
+              expect(value).to.eql(lastCbFired + 1);
  988
+              lastCbFired = value;
  989
+              if (value == 3) {
  990
+                done();
  991
+              }
  992
+            }
  993
+
  994
+            // 2 and 3 will be in the same payload
  995
+            socket.once('flush', function() {
  996
+              socket.send(2, function() { cb(2); });
  997
+              socket.send(3, function() { cb(3); });
  998
+            });
  999
+
  1000
+            socket.send(1, function() { cb(1); });
  1001
+          });
  1002
+        });
  1003
+      });
  1004
+
807 1005
       it('should execute when message sent (polling)', function (done) {
808 1006
         var engine = listen({ allowUpgrades: false }, function (port) {
809 1007
           var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['polling'] });

0 notes on commit 17df993

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