Skip to content

Commit

Permalink
Merge pull request #23 from hoxton-one/upper-limit-buffer-issue-with-…
Browse files Browse the repository at this point in the history
…message

Upper limit buffer issue with message
  • Loading branch information
WolframHempel committed Sep 24, 2015
2 parents ce4f65e + 0c68371 commit f4e73fa
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 22 deletions.
6 changes: 3 additions & 3 deletions dist/deepstream.js
Expand Up @@ -6994,9 +6994,7 @@ Connection.prototype.send = function( message ) {
this._currentPacketMessageCount < this._options.maxMessagesPerPacket ) {
this._sendQueuedMessages();
}

if( this._queuedMessages.length >= this._options.maxMessagesPerPacket &&
this._sendNextPacketTimeout === null ) {
else if( this._sendNextPacketTimeout === null ) {
this._queueNextPacket();
}
};
Expand Down Expand Up @@ -7054,6 +7052,8 @@ Connection.prototype._sendQueuedMessages = function() {

if( this._queuedMessages.length !== 0 ) {
this._queueNextPacket();
} else {
this._sendNextPacketTimeout = null;
}

this._endpoint.send( message );
Expand Down
4 changes: 2 additions & 2 deletions dist/deepstream.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/message/connection.js
Expand Up @@ -118,9 +118,7 @@ Connection.prototype.send = function( message ) {
this._currentPacketMessageCount < this._options.maxMessagesPerPacket ) {
this._sendQueuedMessages();
}

if( this._queuedMessages.length >= this._options.maxMessagesPerPacket &&
this._sendNextPacketTimeout === null ) {
else if( this._sendNextPacketTimeout === null ) {
this._queueNextPacket();
}
};
Expand Down Expand Up @@ -178,6 +176,8 @@ Connection.prototype._sendQueuedMessages = function() {

if( this._queuedMessages.length !== 0 ) {
this._queueNextPacket();
} else {
this._sendNextPacketTimeout = null;
}

this._endpoint.send( message );
Expand Down
32 changes: 20 additions & 12 deletions test-unit/unit/message/connectionSpec.js
Expand Up @@ -189,7 +189,7 @@ describe( 'tries to reconnect if the connection drops unexpectedly', function(){
expect( connection.getState() ).toBe( 'AWAITING_AUTHENTICATION' );
});

it( 'looses the connection', function( done ){
it( 'loses the connection', function( done ){
expect( connection._endpoint.callsToOpen ).toBe( 0 );
connection._endpoint.close();
expect( connection.getState() ).toBe( 'RECONNECTING' );
Expand Down Expand Up @@ -233,7 +233,7 @@ describe( 'tries to reconnect if the connection drops unexpectedly', function(){
expect( connection.getState() ).toBe( 'OPEN' );
});

it( 'looses an authenticated connection', function( done ){
it( 'loses an authenticated connection', function( done ){
connection._endpoint.lastSendMessage = null;
connection._endpoint.close();
expect( connection.getState() ).toBe( 'RECONNECTING' );
Expand Down Expand Up @@ -308,26 +308,34 @@ describe( 'splits messages into smaller packets', function(){
});

it( 'buffers messages greater than maxMessagesPerPacket', function(){
sendMessages( connection, 4, 17 );
sendMessages( connection, 4, 8 );
expect( connection._endpoint.lastSendMessage ).toBe( msg( 'E|EVT|w|4+' ) );
});

it( 'sends buffered messages every timeBetweenSendingQueuedPackages ms', function(done){
it( 'sends messages that are buffered when currentPacketMessageCount exceeds maxMessagesPerPacket', function(done){
var expectedMessage = msg( 'E|EVT|w|5+E|EVT|w|6+E|EVT|w|7+' );

setTimeout(function() {
expect( connection._endpoint.lastSendMessage ).toBe( expectedMessage );
done();
}, 100 );
});

it( 'sends buffered messages that are buffered when messageQueue exceeds maxMessagesPerPacket', function(done){

sendMessages( connection, 9, 17 );

var expectedMessages = [
msg( 'E|EVT|w|5+E|EVT|w|6+E|EVT|w|7+E|EVT|w|8+E|EVT|w|9+' ),
msg( 'E|EVT|w|10+E|EVT|w|11+E|EVT|w|12+E|EVT|w|13+E|EVT|w|14+' ),
msg( 'E|EVT|w|15+E|EVT|w|16+' )
msg( 'E|EVT|w|12+' ),
msg( 'E|EVT|w|13+E|EVT|w|14+E|EVT|w|15+E|EVT|w|16+' )
],
currentlyExpectedMessage = 0,
interval;
currentlyExpectedMessage = 0;

interval = setInterval(function(){
setInterval( function(){
if( connection._endpoint.lastSendMessage === expectedMessages[ currentlyExpectedMessage ] ) {
currentlyExpectedMessage++;
}

if( currentlyExpectedMessage === expectedMessages.length ) {
expect( true ).toBe( true );
done();
}
}, 1);
Expand Down
4 changes: 2 additions & 2 deletions test-unit/unit/record/record-reconnectSpec.js
Expand Up @@ -54,7 +54,7 @@ describe( 'connection losses are handled gracefully', function(){
expect( client._connection._endpoint.lastSendMessage ).toBe( msg( 'R|P|recordB|2|firstname|SWolfram+' ) );
});

it( 'looses the connection', function() {
it( 'loses the connection', function() {
client._connection._endpoint.close();
expect( client.getConnectionState() ).toBe( 'RECONNECTING' );
recordA.set( 'firstname', 'Egon' );
Expand Down Expand Up @@ -86,7 +86,7 @@ describe( 'connection losses are handled gracefully', function(){
expect( deletionCallback ).toHaveBeenCalled();
});

it( 'looses the connection', function() {
it( 'loses the connection', function() {
client._connection._endpoint.close();
expect( client.getConnectionState() ).toBe( 'RECONNECTING' );
});
Expand Down

0 comments on commit f4e73fa

Please sign in to comment.