Permalink
Browse files

added tests for auto and manual buffer flushing

  • Loading branch information...
1 parent afa76b4 commit 76cf0b30cf43fd11786480988c1c9904da5e8353 @gabehollombe gabehollombe committed Apr 23, 2012
Showing with 59 additions and 0 deletions.
  1. +16 −0 support/test-runner/app.js
  2. +43 −0 test/socket.test.js
View
16 support/test-runner/app.js
@@ -158,6 +158,22 @@ suite('socket.test.js', function () {
});
});
+ server('test manual buffer flushing', function (io) {
+ io.sockets.on('connection', function (socket) {
+ socket.on('message', function (msg) {
+ socket.send(msg);
+ });
+ });
+ });
+
+ server('test automatic buffer flushing', function (io) {
+ io.sockets.on('connection', function (socket) {
+ socket.on('message', function (msg) {
+ socket.send(msg);
+ });
+ });
+ });
+
server('test acks sent from client', function (io) {
io.sockets.on('connection', function (socket) {
socket.send('tobi', function () {
View
43 test/socket.test.js
@@ -69,6 +69,49 @@
});
},
+ 'test manual buffer flushing': function (next) {
+ var socket = create();
+
+ socket.socket.options['auto flush'] = false;
+
+ socket.on('error', function (msg) {
+ throw new Error(msg || 'Received an error');
+ });
+
+ socket.on('connect', function () {
+ socket.socket.connected = false;
+ socket.send('buffered');
+ socket.socket.onConnect();
+ socket.socket.flushBuffer();
+
+ socket.on('message', function (msg) {
+ msg.should().equal('buffered');
+ socket.disconnect();
+ next();
+ });
+ });
+ },
+
+ 'test automatic buffer flushing': function (next) {
+ var socket = create();
+
+ socket.on('error', function (msg) {
+ throw new Error(msg || 'Received an error');
+ });
+
+ socket.on('connect', function () {
+ socket.socket.connected = false;
+ socket.send('buffered');
+ socket.socket.onConnect();
+
+ socket.on('message', function (msg) {
+ msg.should().equal('buffered');
+ socket.disconnect();
+ next();
+ });
+ });
+ },
+
'test acks sent from client': function (next) {
var socket = create();

0 comments on commit 76cf0b3

Please sign in to comment.