Skip to content

Commit

Permalink
add tcp-endpoint-mock, which let build fail on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
timaschew committed Jun 23, 2016
1 parent e6e6164 commit 9fd06be
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
8 changes: 7 additions & 1 deletion test/message/connection-endpoint-httpsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ var proxyquire = require( 'proxyquire' ).noCallThru(),
HttpMock = require( '../mocks/http-mock' ),
httpMock = new HttpMock(),
httpsMock = new HttpMock(),
ConnectionEndpoint = proxyquire( '../../src/message/connection-endpoint', { 'engine.io': engineIoMock, 'http': httpMock, 'https': httpsMock } ),
TcpEndpointMock = require( '../mocks/tcp-endpoint-mock' ),
ConnectionEndpoint = proxyquire( '../../src/message/connection-endpoint', {
'engine.io': engineIoMock,
'http': httpMock,
'https': httpsMock,
'../tcp/tcp-endpoint': TcpEndpointMock
} ),
_msg = require( '../test-helper/test-helper' ).msg,
permissionHandlerMock = require( '../mocks/permission-handler-mock' ),
lastAuthenticatedMessage = null,
Expand Down
20 changes: 8 additions & 12 deletions test/tcp/tcp-endpointSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ describe( 'tcp-socket tests', function() {
} );

it( 'emits complete messages', function( done ) {
clientSocket.write( _msg( 'X|Y|1+' ) , 'utf8' );

tcpSocket.once( 'message', function( message ) {
expect( _show( message ) ).toBe( 'X|Y|1+' );
done();
} );
clientSocket.write( _msg( 'X|Y|1+' ) , 'utf8' );
} );

it( 'proxies errors from the underlying socket', function(){
Expand All @@ -44,51 +43,48 @@ describe( 'tcp-socket tests', function() {
});

it( 'concatenates multiple incomplete messages', function( done ) {
clientSocket.write( _msg( 'X|Y|' ) , 'utf8' );

setTimeout( function() {
clientSocket.write( _msg( '2+' ) , 'utf8' );
tcpSocket.once( 'message', function( message ) {
expect( _show( message ) ).toBe( 'X|Y|2+' );
done();
} );
clientSocket.write( _msg( '2+' ) , 'utf8' );
}, 5 );
clientSocket.write( _msg( 'X|Y|' ) , 'utf8' );
} );

it( 'extracts all valid messages if buffer exceeds maxMessageSize ', function( done ) {
clientSocket.write( _msg( 'X|Y|3+Z|Y|4+X|Y|5+X|Y|6' ) , 'utf8' );

tcpSocket.once( 'message', function( message ) {
expect( _show( message ) ).toBe( 'X|Y|3+Z|Y|4+X|Y|5+' );
done();
} );
clientSocket.write( _msg( 'X|Y|3+Z|Y|4+X|Y|5+X|Y|6' ) , 'utf8' );
} );

it( 'concatenates the remained of the last incomplete message after buffer was exceeded', function( done ) {
clientSocket.write( _msg( '+X|Y|7+' ) , 'utf8' );

tcpSocket.once( 'message', function( message ) {
expect( _show( message ) ).toBe( 'X|Y|6+X|Y|7+' );
done();
} );
clientSocket.write( _msg( '+X|Y|7+' ) , 'utf8' );
} );

describe( 'on buffer overrun without valid message', function() {

it( 'emits size exceeded message', function( done ) {
clientSocket.write( _msg( 'X|Y|thismessageisgarbageanddonetooverrunthebuffer' ) , 'utf8' );
clientSocket.once( 'data', function( packet ) {
expect( packet.toString() ).toEqual( _msg( 'X|E|MAXIMUM_MESSAGE_SIZE_EXCEEDED|Received message longer than maxMessageSize+' ) );
done();
} );
clientSocket.write( _msg( 'X|Y|thismessageisgarbageanddonetooverrunthebuffer' ) , 'utf8' );
} );

it( 'parses following messages correctly', function( done ) {
clientSocket.write( _msg( 'stilloverun+X|Y|8+' ) , 'utf8' );
tcpSocket.once( 'message', function( message ) {
expect( _show( message ) ).toBe( 'stilloverun+X|Y|8+' );
done();
} );
clientSocket.write( _msg( 'stilloverun+X|Y|8+' ) , 'utf8' );
} );

} );
Expand All @@ -98,4 +94,4 @@ describe( 'tcp-socket tests', function() {
tcpEndpoint.close();
} );

} );
} );

0 comments on commit 9fd06be

Please sign in to comment.