From f0056a7d1fc9876a88452cedf28131a488b447c2 Mon Sep 17 00:00:00 2001 From: Brandon Nozaki Miller Date: Sun, 10 Jan 2016 03:02:36 -0800 Subject: [PATCH] added TCP client tests back in --- .../jasmineTest/TCP/tcpSocketClient.spec.js | 214 ++++++------------ .../jasmineTest/TCP/tcpSocketServer.spec.js | 7 +- .../jasmineTest/UDP/udpSocketClient.spec.js | 8 +- .../jasmineTest/Unix/unixSocketClient.spec.js | 8 +- 4 files changed, 79 insertions(+), 158 deletions(-) diff --git a/spec/support/jasmineTest/TCP/tcpSocketClient.spec.js b/spec/support/jasmineTest/TCP/tcpSocketClient.spec.js index 9b09896..0ac5d72 100644 --- a/spec/support/jasmineTest/TCP/tcpSocketClient.spec.js +++ b/spec/support/jasmineTest/TCP/tcpSocketClient.spec.js @@ -6,125 +6,101 @@ ipc.config.id ='testClient'; ipc.config.retry = 600; describe('TCP Socket verification of client', - function(){ + function TCPClientSpec(){ it( 'Verify retry attempts by TCP client to connect to the server as per the value set in "maxRetries" parameter.', function(done){ - - let tcpRetryAttempt = 3; //variable created to count the attempt made by client to connect to the server. ipc.config.maxRetries = 3; ipc.config.stopRetrying = false; + //set to -1 because there is an error on the first fail + //before retrying + let errorCount=-1; + ipc.connectToNet( 'tcpFakeServer', - 8002, - function(){ - - ipc.of.tcpFakeServer.on( - 'disconnect', - function(){ - - if(ipc.of.tcpFakeServer.retriesRemaining == 0){ - - expect(tcpRetryAttempt).toBe(ipc.of.tcpFakeServer.retriesRemaining); - expect(ipc.of.tcpFakeServer.socket.destroyed).toBe(true); - - - }else if(ipc.of.tcpFakeServer.retriesRemaining < 0){ - - expect(tcpRetryAttempt).not.toBeLessThan(0); - expect(ipc.of.tcpFakeServer.retriesRemaining).not.toBeLessThan(0); - - - ipc.of.tcpFakeServer.on( - 'error', - function(err){ - console.log('Error is: ', err); - ipc.disconnect('tcpFakeServer'); - } - ); - - } - - tcpRetryAttempt--; + 8002, + function(){ + ipc.of.tcpFakeServer.on( + 'error', + function gotError(err){ + errorCount++; + expect(ipc.of.tcpFakeServer.retriesRemaining).toBe( + ipc.config.maxRetries-errorCount + ); } ); - } + } ); setTimeout( - function(){ - ipc.disconnect('tcpFakeServer'); - done(); - },2500 + function testDelay(){ + expect(errorCount).toBe(ipc.config.maxRetries); + ipc.disconnect('tcpFakeServer'); + done(); + }, + ipc.config.retry*ipc.config.maxRetries + + ipc.config.retry+ipc.config.retry ); + } ); it( 'Verify TCP client does not connect to the TCPserver when "stopRetrying" value is set to true.', - function(done){ - - let tcpRetryAttempt = 3; //variable created to count the attempt made by client to connect to the server. + function testIt(done){ ipc.config.maxRetries = 3; ipc.config.stopRetrying = true; - ipc.config.silent=true; + ipc.silent=true; + + //set to -1 because there is an error on the first fail + //before retrying + let errorCount=-1; ipc.connectToNet( 'tcpFakeServer', - 8002, - function(){ - ipc.of.tcpFakeServer.on( - 'disconnect', - function(){ - - if(ipc.of.tcpFakeServer.retriesRemaining == 3){ - - expect(tcpRetryAttempt).toBe(ipc.of.tcpFakeServer.retriesRemaining); - expect(ipc.of.tcpFakeServer.socket.destroyed).toBe(true); - - } - else if(ipc.of.tcpFakeServer.retriesRemaining < 3){ - - expect(tcpRetryAttempt).not.toBeLessThan(3); - expect(ipc.of.tcpFakeServer.retriesRemaining).not.toBeLessThan(3); - - - ipc.of.tcpFakeServer.on( - 'error', - function(err){ - console.log('Error is: ', err); - ipc.disconnect('tcpFakeServer'); - } - ); - - } - - tcpRetryAttempt--; + 8002, + function open(){ + ipc.of.tcpFakeServer.on( + 'error', + function gotError(err){ + expect(ipc.of.tcpFakeServer.retriesRemaining).toBe(ipc.config.maxRetries); + errorCount++; } ); - } + } ); setTimeout( - function(){ - ipc.disconnect('tcpFakeServer'); - done(); - },700 + function testDelay(){ + expect(errorCount).toBe(0); + expect(ipc.of.tcpFakeServer.retriesRemaining).toBe(ipc.config.maxRetries); + ipc.disconnect('tcpFakeServer'); + done(); + }, + ipc.config.retry*ipc.config.maxRetries ); } ); it( 'Verify TCP client connects to server named "tcpServer" and receives message.', - function(done){ + function testIt(done){ ipc.connectToNet( 'tcpServer', 8300, - function(){ + function open(){ ipc.of.tcpServer.on( 'connect', - function(){ + function connected(){ + ipc.of.tcpServer.on( + 'message', + function(data,socket){ + expect(data.id).toBe('tcpServer'); + expect(data.message).toBe('I am TCP server!'); + testDone(); + } + ); ipc.of.tcpServer.emit( 'message', @@ -133,78 +109,24 @@ describe('TCP Socket verification of client', message : 'Hello from testClient.' } ); + } + ); - ipc.of.tcpServer.on( - 'message', - function(data,socket){ - - expect(data.id).toBe('tcpServer'); - expect(data.message).toBe('I am TCP server!'); - ipc.disconnect('tcpServer'); - done(); - } - ); + ipc.of.tcpServer.on( + 'error', + function testError(err){ + expect(err).toBe(false); + testDone(); } ); } ); + + function testDone(){ + ipc.disconnect('tcpServer'); + done(); + } } ); - - it( - 'Verify TCP client queues the requests being sent to the server synchronously until it receives the response from server.', - function(done){ - - ipc.config.sync = true; - let responseCounter = 0; - - ipc.connectToNet( - 'tcpServerSync', - 8400, - function(){ - ipc.of.tcpServerSync.on( - 'connect', - function(){ - - for(let i=0; i<5; i++){ - - ipc.of.tcpServerSync.emit( - 'message', - { - id : ipc.config.id, - message : 'TCP Client Request '+ i - } - ); - } - - ipc.of.tcpServerSync.on( - 'message', - function(data){ - if (data.message != null){ - responseCounter++; - expect(data.message).toBe('Response from TCP server'); - } - - if (responseCounter == 5){ - expect(responseCounter).toBe(5); - ipc.disconnect('tcpServerSync'); - done(); - } - } - ); - - ipc.of.tcpServerSync.on( - 'error', - function(err){ - console.log('Error is: ', err); done(); - ipc.disconnect('tcpServerSync'); - } - ); - } - ); - } - ); - } - ); - } + } ); diff --git a/spec/support/jasmineTest/TCP/tcpSocketServer.spec.js b/spec/support/jasmineTest/TCP/tcpSocketServer.spec.js index d969e5c..7b4d555 100644 --- a/spec/support/jasmineTest/TCP/tcpSocketServer.spec.js +++ b/spec/support/jasmineTest/TCP/tcpSocketServer.spec.js @@ -6,9 +6,8 @@ ipc.config.id ='testWorld'; ipc.config.retry = 1000; describe('TCP Socket verification of server', - function(){ - - it( + function TCPSocketSpec(){ + it( 'Verify TCP server detects only 1 client out of 2 clients and receives message.', function(done){ @@ -44,5 +43,5 @@ describe('TCP Socket verification of server', } ); - } + } ); diff --git a/spec/support/jasmineTest/UDP/udpSocketClient.spec.js b/spec/support/jasmineTest/UDP/udpSocketClient.spec.js index 9d99e32..de88624 100644 --- a/spec/support/jasmineTest/UDP/udpSocketClient.spec.js +++ b/spec/support/jasmineTest/UDP/udpSocketClient.spec.js @@ -4,7 +4,7 @@ const ipc = require('../../../../node-ipc'); describe( 'UDP Socket verification.', - function testDescription(){ + function UDPSocketSpec(){ it( 'Verify UDP server of type udp4 connects to UDP server named "udp4Server" and receives message.', function testIt(done){ @@ -29,7 +29,7 @@ describe( ipc.server.on( 'error', - function(err){ + function gotErr(err){ expect(err).toBe(false); testDone(); } @@ -71,7 +71,7 @@ describe( '::1', clientPort, 'udp6', - function(){ + function serverStarted(){ ipc.server.on( 'message', function(data,socket){ @@ -83,7 +83,7 @@ describe( ipc.server.on( 'error', - function(err){ + function gotErr(err){ expect(err).toBe(false); testDone(); } diff --git a/spec/support/jasmineTest/Unix/unixSocketClient.spec.js b/spec/support/jasmineTest/Unix/unixSocketClient.spec.js index 30d3e37..bc028b1 100644 --- a/spec/support/jasmineTest/Unix/unixSocketClient.spec.js +++ b/spec/support/jasmineTest/Unix/unixSocketClient.spec.js @@ -6,7 +6,7 @@ ipc.config.id ='testClient'; ipc.config.retry = 600; describe('Test Cases for Unix client: ', - function describeTests(){ + function UnixClientSpec(){ it( 'Verify retry attempts by Unix client to connect to the Unix server as per the value set in "maxRetries" parameter.', function testIt(done){ @@ -46,7 +46,7 @@ describe('Test Cases for Unix client: ', it( 'Verify Unix client does not connect to the unix server when "stopRetrying" value is set to true.', - function(done){ + function testIt(done){ ipc.config.maxRetries = 3; ipc.config.stopRetrying = true; @@ -104,7 +104,7 @@ describe('Test Cases for Unix client: ', ipc.of.unixServer.on( 'error', - function(err){ + function gotErr(err){ expect(err).toBe(false); testDone(); } @@ -156,7 +156,7 @@ describe('Test Cases for Unix client: ', ipc.of.unixServerSync.on( 'message', - function(data){ + function gotMessage(data){ expect(data.message).toBe('Response from unix server'); responseCounter++;