From cef306eb4b4d615f7459075a08b8929084af7b02 Mon Sep 17 00:00:00 2001 From: nileshprasad Date: Thu, 7 Jan 2016 15:55:06 -0800 Subject: [PATCH] Added test case for Sync parameter for TCP and Unix, Added testFile.js which helps in executing all test scripts and dependent file in same terminal --- spec/support/jasmine.json | 10 +- .../jasmineTest/TCP/tcpSocketClient.spec.js | 221 ++++++++++ .../jasmineTest/TCP/tcpSocketServer.spec.js | 48 +++ .../jasmineTest/UDP/udpSocketClient.spec.js | 93 ++++ .../jasmineTest/Unix/unixSocketClient.spec.js | 225 ++++++++++ .../jasmineTest/Unix/unixSocketServer.spec.js | 47 ++ .../jasmineTest/clientTestCases.spec.js | 408 ------------------ .../jasmineTest/rawBufferClientAscii.spec.js | 61 --- .../jasmineTest/rawBufferServerAscii.js | 39 -- .../jasmineTest/serverTestCases.spec.js | 110 ----- spec/support/jasmineTest/tcpServerSync.js | 39 ++ .../jasmineTest/tcpSocketClient.spec.js | 133 ------ .../jasmineTest/tcpSocketServer.spec.js | 102 ----- spec/support/jasmineTest/testFile.js | 17 + spec/support/jasmineTest/udp4Server.js | 4 +- spec/support/jasmineTest/udp6Server.js | 6 +- spec/support/jasmineTest/unixServerSync.js | 36 ++ 17 files changed, 739 insertions(+), 860 deletions(-) create mode 100644 spec/support/jasmineTest/TCP/tcpSocketClient.spec.js create mode 100644 spec/support/jasmineTest/TCP/tcpSocketServer.spec.js create mode 100644 spec/support/jasmineTest/UDP/udpSocketClient.spec.js create mode 100644 spec/support/jasmineTest/Unix/unixSocketClient.spec.js create mode 100644 spec/support/jasmineTest/Unix/unixSocketServer.spec.js delete mode 100644 spec/support/jasmineTest/clientTestCases.spec.js delete mode 100644 spec/support/jasmineTest/rawBufferClientAscii.spec.js delete mode 100644 spec/support/jasmineTest/rawBufferServerAscii.js delete mode 100644 spec/support/jasmineTest/serverTestCases.spec.js create mode 100644 spec/support/jasmineTest/tcpServerSync.js delete mode 100644 spec/support/jasmineTest/tcpSocketClient.spec.js delete mode 100644 spec/support/jasmineTest/tcpSocketServer.spec.js create mode 100644 spec/support/jasmineTest/testFile.js create mode 100644 spec/support/jasmineTest/unixServerSync.js diff --git a/spec/support/jasmine.json b/spec/support/jasmine.json index 3a079a7..9f6388a 100644 --- a/spec/support/jasmine.json +++ b/spec/support/jasmine.json @@ -2,8 +2,14 @@ "spec_dir": "spec", "spec_files": [ - "/support/jasmineTest/clientTestCases.spec.js", - "/support/jasmineTest/serverTestCases.spec.js" + "/support/jasmineTest/testFile.js", + "/support/jasmineTest/Unix/unixSocketClient.spec.js", + + "/support/jasmineTest/UDP/udpSocketClient.spec.js", + "/support/jasmineTest/TCP/tcpSocketClient.spec.js", + + "/support/jasmineTest/Unix/unixSocketServer.spec.js", + "/support/jasmineTest/TCP/tcpSocketServer.spec.js" ] diff --git a/spec/support/jasmineTest/TCP/tcpSocketClient.spec.js b/spec/support/jasmineTest/TCP/tcpSocketClient.spec.js new file mode 100644 index 0000000..0f04e1b --- /dev/null +++ b/spec/support/jasmineTest/TCP/tcpSocketClient.spec.js @@ -0,0 +1,221 @@ +var ipc = require('../../../../node-ipc'); + + ipc.config.id ='testClient'; + ipc.config.retry = 600; + + +describe('TCP Socket verification of client', + function(){ + + it( + 'Verify retry attempts by TCP client to connect to the server as per the value set in "maxRetries" parameter.', + function(done){ + + var tcpRetryAttempt = 3; //variable created to count the attempt made by client to connect to the server. + ipc.config.maxRetries = 3; + ipc.config.stopRetrying = false; + ipc.config.silent= false; + + 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--; + } + ); + } + ); + + // Wait time is added to verify the fail case scenario of additional retry attempt by client than expected. + setTimeout( + function(){ + ipc.disconnect('tcpFakeServer'); + done(); + },2500 + ); + + } + ); + + it( + 'Verify TCP client does not connect to the TCPserver when "stopRetrying" value is set to true.', + function(done){ + + var tcpRetryAttempt = 3; //variable created to count the attempt made by client to connect to the server. + ipc.config.maxRetries = 3; + ipc.config.stopRetrying = true; + + 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--; + } + ); + } + ); + + // Wait time is added to verify the fail case scenario of additional retry attempt by client than expected. + setTimeout( + function(){ + ipc.disconnect('tcpFakeServer'); + done(); + },700 + ); + } + ); + + it( + 'Verify TCP client connects to server named "tcpServer" and receives message.', + function(done){ + ipc.connectToNet( + 'tcpServer', + 8300, + function(){ + ipc.of.tcpServer.on( + 'connect', + function(){ + + ipc.of.tcpServer.emit( + 'message', + { + id : ipc.config.id, + 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(); + } + ); + + } + ); + } + ); + } + ); + + 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; + var responseCounter = 0; + + ipc.connectToNet( + 'tcpServerSync', + 8400, + function(){ + ipc.of.tcpServerSync.on( + 'connect', + function(){ + + for(var 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 new file mode 100644 index 0000000..6370d68 --- /dev/null +++ b/spec/support/jasmineTest/TCP/tcpSocketServer.spec.js @@ -0,0 +1,48 @@ +var ipc = require('../../../../node-ipc'); + + ipc.config.id ='testWorld'; + ipc.config.retry = 1000; + + +describe('TCP Socket verification of server', + function(){ + + it( + 'Verify TCP server detects only 1 client out of 2 clients and receives message.', + function(done){ + + var clientCounter =0; + ipc.config.maxConnections=1; + ipc.config.networkPort=8500; + + ipc.serveNet( + function(){ + ipc.server.on( + 'app.message', + function(data,socket){ + + clientCounter++; + + expect(data.id).toBe('tcpClient'); + expect(data.message).toBe('I am TCP client.'); + + } + ); + + setTimeout( + function(){ + expect(clientCounter).toBe(1); + + done(); + },2000 + ); + } + ); + + ipc.server.start(); + + } + ); + } +); + diff --git a/spec/support/jasmineTest/UDP/udpSocketClient.spec.js b/spec/support/jasmineTest/UDP/udpSocketClient.spec.js new file mode 100644 index 0000000..5f575e0 --- /dev/null +++ b/spec/support/jasmineTest/UDP/udpSocketClient.spec.js @@ -0,0 +1,93 @@ +var ipc = require('../../../../node-ipc'); + + ipc.config.id ='testClient'; + ipc.config.retry = 600; + + +describe( + 'UDP Socket verification.', + function(){ + it( + 'Verify UDP server of type udp4 connects to UDP server named "udp4Server" and receives message.', + function(done){ + ipc.serveNet( + 8001, + 'udp4', + function(){ + ipc.server.on( + 'message', + function(data,socket){ + expect(data.id).toBe('udpServer'); + expect(data.message).toBe('I am UDP4 server!'); + done(); + } + ); + + ipc.server.emit( + { + address : 'localhost', + port : ipc.config.networkPort + }, + 'message', + { + id : ipc.config.id, + message : 'I am testClient' + } + ); + + ipc.server.on( + 'error', + function(err){ + console.log('Error is: ', err); + + } + ); + } + ); + ipc.server.start(); + } + ); + + it( + 'Verify UDP server of type udp6 connects to UDP server named "udp6Server" and receives message.', + function(done){ + + ipc.serveNet( + '::1', + 8010, + 'udp6', + function(){ + ipc.server.on( + 'message', + function(data,socket){ + expect(data.id).toBe('udp6Server'); + expect(data.message).toBe('I am UDP6 server!'); + done(); + } + ); + + ipc.server.emit( + { + address : 'localhost', + port : ipc.config.networkPort + }, + 'message', + { + id : ipc.config.id, + message : 'I am testClient' + } + ); + + ipc.server.on( + 'error', + function(err){ + console.log('Error is: ', err); + } + ); + } + ); + ipc.server.start(); + } + ); + } +); \ No newline at end of file diff --git a/spec/support/jasmineTest/Unix/unixSocketClient.spec.js b/spec/support/jasmineTest/Unix/unixSocketClient.spec.js new file mode 100644 index 0000000..9b579d5 --- /dev/null +++ b/spec/support/jasmineTest/Unix/unixSocketClient.spec.js @@ -0,0 +1,225 @@ +var ipc = require('../../../../node-ipc'); + + ipc.config.id ='testClient'; + ipc.config.retry = 600; + + +describe('Test Cases for Unix client: ', + function(){ + + it( + 'Verify retry attempts by Unix client to connect to the Unix server as per the value set in "maxRetries" parameter.', + function(done){ + + var retryAttempt = 3; //variable created to count the attempt made by client to connect to the server. + ipc.config.maxRetries = 3; + ipc.config.silent= true; + + ipc.connectTo( + 'fakeworld', + function(){ + + ipc.of.fakeworld.on( + 'disconnect', + function(){ + + if(ipc.of.fakeworld.retriesRemaining == 0){ + + expect(retryAttempt).toBe(ipc.of.fakeworld.retriesRemaining); + expect(ipc.of.fakeworld.socket.destroyed).toBe(true); + + } + else if(ipc.of.fakeworld.retriesRemaining < 0){ + + expect(retryAttempt).not.toBeLessThan(0); + expect(ipc.of.fakeworld.retriesRemaining).not.toBeLessThan(0); + + + ipc.of.fakeworld.on( + 'error', + function(err){ + console.log('Error is: ', err); + ipc.disconnect('fakeworld'); + } + ); + + } + + retryAttempt--; + } + ); + } + ); + + // Wait time is added to verify the fail case scenario of additional retry attempt by client than expected. + setTimeout( + function(){ + ipc.disconnect('fakeworld'); + done(); + },2500 + ); + + + } + ); + + it( + 'Verify Unix client does not connect to the unix server when "stopRetrying" value is set to true.', + function(done){ + + var retryAttempt = 3; //variable created to count the attempt made by client to connect to the server. + ipc.config.maxRetries = 3; + ipc.config.stopRetrying = true; + + + ipc.connectTo( + 'fakeworld', + function(){ + ipc.of.fakeworld.on( + 'disconnect', + function(){ + + if(ipc.of.fakeworld.retriesRemaining == 3){ + + expect(retryAttempt).toBe(ipc.of.fakeworld.retriesRemaining); + expect(ipc.of.fakeworld.socket.destroyed).toBe(true); + + } + else if(ipc.of.fakeworld.retriesRemaining < 3){ + + expect(retryAttempt).not.toBeLessThan(3); + expect(ipc.of.fakeworld.retriesRemaining).not.toBeLessThan(3); + + + ipc.of.fakeworld.on( + 'error', + function(err){ + console.log('Error is: ', err); + ipc.disconnect('fakeworld'); + } + ); + + } + + retryAttempt--; + } + ); + } + ); + + // Wait time is added to verify the fail case scenario of additional retry attempt by client than expected. + setTimeout( + function(){ + ipc.disconnect('fakeworld'); + done(); + },700 + ); + } + ); + + + it( + 'Verify unix client connects to "unixServer" and receives message.', + function(done){ + ipc.connectTo( + 'unixServer', + '/tmp/app.unixServer', + function(){ + ipc.of.unixServer.on( + 'connect', + function(){ + ipc.of.unixServer.emit( + 'message', + { + id : ipc.config.id, + message : 'Hello from Client.' + } + ); + + ipc.of.unixServer.on( + 'message', + function(data){ + + expect(data.id).toBe('unixServer'); + expect(data.message).toBe('I am unix server!'); + ipc.disconnect('unixServer'); + done(); + } + ); + + ipc.of.unixServer.on( + 'error', + function(err){ + console.log('Error is: ', err); done(); + ipc.disconnect('unixServer'); + } + ); + + } + ); + } + ); + } + ); + + it( + 'Verify unix client queues the requests being sent to the server synchronously until it receives the response from server.', + function(done){ + + ipc.config.sync = true; + var responseCounter = 0; + + ipc.connectTo( + 'unixServerSync', + '/tmp/app.unixServerSync', + function(){ + ipc.of.unixServerSync.on( + 'connect', + function(){ + + for(var i=0; i<5; i++){ + + ipc.of.unixServerSync.emit( + 'message', + { + id : ipc.config.id, + message : 'Unix Client Request '+ i + + } + ); + } + + ipc.of.unixServerSync.on( + 'message', + function(data){ + if (data.message != null){ + responseCounter++; + expect(data.message).toBe('Response from unix server'); + } + + if (responseCounter == 5){ + expect(responseCounter).toBe(5); + ipc.disconnect('unixServerSync'); + done(); + } + } + ); + + ipc.of.unixServerSync.on( + 'error', + function(err){ + console.log('Error is: ', err); done(); + ipc.disconnect('unixServerSync'); + } + ); + + } + ); + } + ); + } + ); + // End of test cases for Unix + } +); + diff --git a/spec/support/jasmineTest/Unix/unixSocketServer.spec.js b/spec/support/jasmineTest/Unix/unixSocketServer.spec.js new file mode 100644 index 0000000..fc46cb3 --- /dev/null +++ b/spec/support/jasmineTest/Unix/unixSocketServer.spec.js @@ -0,0 +1,47 @@ +var ipc = require('../../../../node-ipc'); + + ipc.config.id ='testWorld'; + ipc.config.retry = 1000; + + +describe('Test Cases for server: ', + function(){ + // Unix server verification // + it( + 'Verify unix server detects only 1 client out of 2 clients and receives message.', + function(done){ + + var clientCounter =0; + ipc.config.maxConnections=1; + ipc.config.networkPort='/tmp/app.testWorld'; + + ipc.serve( + function(){ + ipc.server.on( + 'message', + function(data,socket){ + + clientCounter++; + expect(data.id).toBe('unixClient'); + expect(data.message).toBe('I am unix client.'); + + } + ); + + setTimeout( + function(){ + expect(clientCounter).toBe(1); + + done(); + },2000 + ); + } + ); + + ipc.server.start(); + + } + ); + } +); + diff --git a/spec/support/jasmineTest/clientTestCases.spec.js b/spec/support/jasmineTest/clientTestCases.spec.js deleted file mode 100644 index 46ef09f..0000000 --- a/spec/support/jasmineTest/clientTestCases.spec.js +++ /dev/null @@ -1,408 +0,0 @@ -var ipc = require('../../../../node-ipc'); - - ipc.config.id ='testClient'; - ipc.config.retry = 600; - - -describe('Test Cases for client: ', - function(){ - - it( - 'Verify retry attempts by Unix client to connect to the Unix server as per the value set in "maxRetries" parameter.', - function(done){ - - var retryAttempt = 3; //variable created to count the attempt made by client to connect to the server. - ipc.config.maxRetries = 3; - ipc.config.silent= true; - - ipc.connectTo( - 'fakeworld', - function(){ - - ipc.of.fakeworld.on( - 'disconnect', - function(){ - - if(ipc.of.fakeworld.retriesRemaining == 0){ - - expect(retryAttempt).toBe(ipc.of.fakeworld.retriesRemaining); - expect(ipc.of.fakeworld.socket.destroyed).toBe(true); - - } - else if(ipc.of.fakeworld.retriesRemaining < 0){ - - expect(retryAttempt).not.toBeLessThan(0); - expect(ipc.of.fakeworld.retriesRemaining).not.toBeLessThan(0); - - - ipc.of.fakeworld.on( - 'error', - function(err){ - console.log('Error is: ', err); - ipc.disconnect('fakeworld'); - } - ); - - } - - retryAttempt--; - } - ); - } - ); - - // Wait time is added to verify the fail case scenario of additional retry attempt by client than expected. - setTimeout( - function(){ - ipc.disconnect('fakeworld'); - done(); - },2500 - ); - - - } - ); - - it( - 'Verify Unix client does not connect to the unix server when "stopRetrying" value is set to true.', - function(done){ - - var retryAttempt = 3; //variable created to count the attempt made by client to connect to the server. - ipc.config.maxRetries = 3; - ipc.config.stopRetrying = true; - - - ipc.connectTo( - 'fakeworld', - function(){ - ipc.of.fakeworld.on( - 'disconnect', - function(){ - - if(ipc.of.fakeworld.retriesRemaining == 3){ - - expect(retryAttempt).toBe(ipc.of.fakeworld.retriesRemaining); - expect(ipc.of.fakeworld.socket.destroyed).toBe(true); - - } - else if(ipc.of.fakeworld.retriesRemaining < 3){ - - expect(retryAttempt).not.toBeLessThan(3); - expect(ipc.of.fakeworld.retriesRemaining).not.toBeLessThan(3); - - - ipc.of.fakeworld.on( - 'error', - function(err){ - console.log('Error is: ', err); - ipc.disconnect('fakeworld'); - } - ); - - } - - retryAttempt--; - } - ); - } - ); - - // Wait time is added to verify the fail case scenario of additional retry attempt by client than expected. - setTimeout( - function(){ - ipc.disconnect('fakeworld'); - done(); - },700 - ); - } - ); - - - it( - 'Verify unix client connects to "unixServer" and receives message.', - function(done){ - ipc.connectTo( - 'unixServer', - '/tmp/app.unixServer', - function(){ - ipc.of.unixServer.on( - 'connect', - function(){ - ipc.of.unixServer.emit( - 'message', - { - id : ipc.config.id, - message : 'Hello from Client.' - } - ); - - ipc.of.unixServer.on( - 'message', - function(data){ - - expect(data.id).toBe('unixServer'); - expect(data.message).toBe('I am unix server!'); - ipc.disconnect('unixServer'); - done(); - } - ); - - ipc.of.unixServer.on( - 'error', - function(err){ - console.log('Error is: ', err); done(); - ipc.disconnect('unixServer'); - } - ); - - } - ); - } - ); - } - ); - - // UDP Test Cases // - it( - 'Verify UDP server "testClient" connects to UDP server named "udpServer" and receives message.', - function(done){ - ipc.serveNet( - 8001, - 'udp4', - function(){ - ipc.server.on( - 'message', - function(data,socket){ - expect(data.id).toBe('udpServer'); - expect(data.message).toBe('I am UDP server!'); - done(); - } - ); - - ipc.server.emit( - { - address : 'localhost', - port : ipc.config.networkPort - }, - 'message', - { - id : ipc.config.id, - message : 'I am client' - } - ); - - ipc.server.on( - 'error', - function(err){ - console.log('Error is: ', err); - - } - ); - } - ); - ipc.server.start(); - } - ); - - it( - 'Verify UDP server of type udp6 connects to UDP server named "udp6Server" and receives message.', - function(done){ - - ipc.serveNet( - 8001, - 'udp6', - function(){ - ipc.server.on( - 'message', - function(data,socket){ - expect(data.id).toBe('udp6Server'); - expect(data.message).toBe('I am UDP6 server!'); - done(); - } - ); - - ipc.server.emit( - { - address : 'localhost', - port : ipc.config.networkPort - }, - 'message', - { - id : ipc.config.id, - message : 'I am testClient' - } - ); - - ipc.server.on( - 'error', - function(err){ - console.log('Error is: ', err); - - } - ); - } - ); - ipc.server.start(); - } - ); - - - // TCP Client test cases - - it( - 'Verify retry attempts by TCP client to connect to the server as per the value set in "maxRetries" parameter.', - function(done){ - - var tcpRetryAttempt = 3; //variable created to count the attempt made by client to connect to the server. - ipc.config.maxRetries = 3; - ipc.config.stopRetrying = false; - ipc.config.silent= false; - - 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--; - } - ); - } - ); - - // Wait time is added to verify the fail case scenario of additional retry attempt by client than expected. - setTimeout( - function(){ - ipc.disconnect('tcpFakeServer'); - done(); - },2500 - ); - - } - ); - - it( - 'Verify TCP client does not connect to the TCPserver when "stopRetrying" value is set to true.', - function(done){ - - var tcpRetryAttempt = 3; //variable created to count the attempt made by client to connect to the server. - ipc.config.maxRetries = 3; - ipc.config.stopRetrying = true; - - 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--; - } - ); - } - ); - - // Wait time is added to verify the fail case scenario of additional retry attempt by client than expected. - setTimeout( - function(){ - ipc.disconnect('tcpFakeServer'); - done(); - },700 - ); - } - ); - - it( - 'Verify TCP client connects to server named "tcpServer" and receives message.', - function(done){ - ipc.connectToNet( - 'tcpServer', - 8300, - function(){ - ipc.of.tcpServer.on( - 'connect', - function(){ - - ipc.of.tcpServer.emit( - 'message', - { - id : ipc.config.id, - 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(); - } - ); - - } - ); - } - ); - } - ); - - - - // End test cases - - - } -); - diff --git a/spec/support/jasmineTest/rawBufferClientAscii.spec.js b/spec/support/jasmineTest/rawBufferClientAscii.spec.js deleted file mode 100644 index 623e004..0000000 --- a/spec/support/jasmineTest/rawBufferClientAscii.spec.js +++ /dev/null @@ -1,61 +0,0 @@ -var ipc = require('../../../../node-ipc'); - - ipc.config.id ='testClient'; - ipc.config.retry = 600; - - -describe('Raw Buffer tests: ', - function(){ - - it( - 'Verify data in hex is received from the server.', - function(done){ - - ipc.config.rawBuffer=true; - ipc.config.encoding='hex'; - - ipc.connectToNet( - 'rawBufferWorldAscii', - 8000, - function(){ - ipc.of.rawBufferWorldAscii.on( - 'connect', - function(){ - ipc.log('## connected to world ##'.rainbow, ipc.config.delay); - - } - ); - - ipc.of.rawBufferWorldAscii.on( - 'data', - function(data){ - console.log('obtained data is: ',data); - //expect(data).toBe('Buffer 31 30 30 61 30 31'); - done(); - //ipc.log('got a message from world : '.debug, data,data.toString()); - } - ); - - - ipc.of.rawBufferWorldAscii.on( - 'error', - function(err){ - console.log('Error is: ', err); - - } - ); - - } - ); - - } - ); - - - - - - - } -); - diff --git a/spec/support/jasmineTest/rawBufferServerAscii.js b/spec/support/jasmineTest/rawBufferServerAscii.js deleted file mode 100644 index d72a592..0000000 --- a/spec/support/jasmineTest/rawBufferServerAscii.js +++ /dev/null @@ -1,39 +0,0 @@ -var ipc=require('../../../node-ipc'); - -/***************************************\ - * - * You should start both hello and world - * then you will see them communicating. - * - * *************************************/ - -ipc.config.id = 'rawBufferWorldAscii'; -ipc.config.retry= 1500; - -ipc.config.rawBuffer=true; -ipc.config.encoding='hex'; - - - -ipc.serveNet( - function(){ - ipc.server.on( - 'connect', - function(socket){ - ipc.server.emit( - socket, - [0x10,0x0A,0x01] - //'hello' - ); - } - ); - - - - } -); - - -ipc.server.start(); - - diff --git a/spec/support/jasmineTest/serverTestCases.spec.js b/spec/support/jasmineTest/serverTestCases.spec.js deleted file mode 100644 index 323f248..0000000 --- a/spec/support/jasmineTest/serverTestCases.spec.js +++ /dev/null @@ -1,110 +0,0 @@ -var ipc = require('../../../../node-ipc'); - - ipc.config.id ='testWorld'; - ipc.config.retry = 1000; - - -describe('Test Cases for server: ', - function(){ - // Unix server verification // - it( - 'Verify unix server detects only 1 client out of 2 clients and receives message.', - function(done){ - console.log('ENTERED TEST 2- unixServer.'); - - var clientCounter =0; - ipc.config.maxConnections=1; - ipc.config.networkPort='/tmp/app.testWorld'; - - ipc.serve( - function(){ - ipc.server.on( - 'message', - function(data,socket){ - - clientCounter++; - expect(data.id).toBe('unixClient'); - expect(data.message).toBe('I am unix client.'); - - } - ); - - setTimeout( - function(){ - expect(clientCounter).toBe(1); - - done(); - },2000 - ); - } - ); - - ipc.server.start(); - - } - ); - - // TCP server verification // - it( - 'Verify TCP server detects only 1 client out of 2 clients and receives message.', - function(done){ - - console.log('ENTERED TEST 2- tcpServer.'); - var clientCounter =0; - ipc.config.id ='testWorld'; - ipc.config.retry = 1000; - - ipc.config.maxConnections=1; - ipc.config.networkPort=8500; - - ipc.serveNet( - function(){ - ipc.server.on( - 'app.message', - function(data,socket){ - - clientCounter++; - - expect(data.id).toBe('tcpClient'); - expect(data.message).toBe('I am TCP client.'); - - } - ); - - setTimeout( - function(){ - expect(clientCounter).toBe(1); - - done(); - },2000 - ); - } - ); - - ipc.server.start(); - - } - ); - - - - - - - - - - - - - - - - - - - - - } -); - diff --git a/spec/support/jasmineTest/tcpServerSync.js b/spec/support/jasmineTest/tcpServerSync.js new file mode 100644 index 0000000..8d2d498 --- /dev/null +++ b/spec/support/jasmineTest/tcpServerSync.js @@ -0,0 +1,39 @@ +var ipc=require('../../../node-ipc'); + +/***************************************\ + * + * You should start both hello and world + * then you will see them communicating. + * + * *************************************/ + +ipc.config.id = 'tcpServerSync'; +ipc.config.retry= 1500; +ipc.config.networkPort = 8400; + + +ipc.serveNet( + function(){ + ipc.server.on( + 'message', + function(data,socket){ + setTimeout( + function(){ + ipc.server.emit( + socket, + 'message', + { + id : ipc.config.id, + message : 'Response from TCP server' + + } + ); + },900 + ); + } + ); + } +); + + +ipc.server.start(); diff --git a/spec/support/jasmineTest/tcpSocketClient.spec.js b/spec/support/jasmineTest/tcpSocketClient.spec.js deleted file mode 100644 index 66c9de7..0000000 --- a/spec/support/jasmineTest/tcpSocketClient.spec.js +++ /dev/null @@ -1,133 +0,0 @@ -var ipc = require('../../../../node-ipc'); - - ipc.config.id ='testClient'; - ipc.config.retry = 600; - - -describe('Unix Socket verification of client', - function(){ - - it( - 'Verify retry attempts by TCP client to connect to the server as per the value set in "maxRetries" parameter.', - function(done){ - - var retryAttempt = 3; //variable created to count the attempt made by client to connect to the server. - ipc.config.maxRetries = 3; - //ipc.config.silent= true; - - ipc.connectToNet( - 'fakeworld', - 8001, - function(){ - ipc.of.fakeworld.on( - 'disconnect', - function(){ - - if(ipc.of.fakeworld.retriesRemaining == 1){ - expect(retryAttempt).toBe(ipc.of.fakeworld.retriesRemaining); - done(); - } - retryAttempt--; - } - ); - - ipc.of.fakeworld.on( - 'error', - function(err){ - console.log('Error is: ', err); - - } - ); - - } - ); - - } - ); - - it( - 'Verify TCP client does not connect to the TCPserver when "stopRetrying" value is set to true.', - function(done){ - - var retryAttempt = 3; //variable created to count the attempt made by client to connect to the server. - ipc.config.maxRetries = 3; - ipc.config.stopRetrying = true; - - ipc.connectToNet( - 'fakeworld', - 8001, - function(){ - ipc.of.fakeworld.on( - 'disconnect', - function(){ - - retryAttempt--; - console.log('var value of retryAttempt: ',retryAttempt); - } - ); - - setTimeout( - function(){ - expect(retryAttempt).toBe(ipc.of.fakeworld.retriesRemaining); - expect(ipc.of.fakeworld.retriesRemaining).toBe(ipc.config.maxRetries); - - done(); - },10 - ); - - ipc.of.fakeworld.on( - 'error', - function(err){ - console.log('Error is: ', err); - - } - ); - - } - ); - } - ); - - - it( - 'Verify TCP client connects to server named "world" and receives message.', - function(done){ - ipc.connectToNet( - 'world', - function(){ - ipc.of.world.on( - 'connect', - function(){ - - ipc.of.world.emit( - 'app.message', - { - id : ipc.config.id, - message : 'Hello from Client.' - } - ); - - ipc.of.world.on( - 'app.message', - function(data,socket){ - console.log('data from world: ', data.id, data.message); - - expect(data.id).toBe('world'); - expect(data.message).toBe('I am world!'); - done(); - } - ); - - } - ); - } - ); - } - ); - - - - - } -); - diff --git a/spec/support/jasmineTest/tcpSocketServer.spec.js b/spec/support/jasmineTest/tcpSocketServer.spec.js deleted file mode 100644 index b0e9e5c..0000000 --- a/spec/support/jasmineTest/tcpSocketServer.spec.js +++ /dev/null @@ -1,102 +0,0 @@ -var ipc = require('../../../../node-ipc'); - - ipc.config.id ='testWorld'; - ipc.config.retry = 1000; - - -describe('Unix Socket verification of server', - function(){ - - it( - 'Verify server detects only 1 client out of 2 clients and receives message.', - function(done){ - - var clientCounter =0; - ipc.config.maxConnections=1; - - ipc.serveNet( - function(){ - ipc.server.on( - 'app.message', - function(data,socket){ - - clientCounter++; - - expect(data.id).toBe('client1'); - expect(data.message).toBe('I am client1'); - - } - ); - - setTimeout( - function(){ - expect(clientCounter).toBe(1); - - done(); - },2000 - ); - } - ); - - ipc.server.start(); - - } - ); - - /* - xit( - 'Verify server detects clients named "client1" and receives message.', - function(done){ - ipc.serve( - function(){ - ipc.server.on( - 'app.message', - function(data,socket){ - - console.log('Client connected is: ', data.id); - expect(data.id).toBe('client1'); - expect(data.message).toBe('I am client1'); - done(); - } - ); - } - ); - ipc.server.start(); - - } - ); - - xit( - 'Verify server receives disconnection from the connected client.', - function(done){ - - ipc.serve( - function(){ - ipc.server.on( - 'app.message', - function(data,socket){ - console.log('Client connected is: ', data.id); - - ipc.server.on( - 'close', - function(){ - console.log('Client closed: ', data.id); - done(); - } - ); - - } - ); - - - } - ); - - ipc.server.start(); - - } - ); - */ - } -); - diff --git a/spec/support/jasmineTest/testFile.js b/spec/support/jasmineTest/testFile.js new file mode 100644 index 0000000..e1b5975 --- /dev/null +++ b/spec/support/jasmineTest/testFile.js @@ -0,0 +1,17 @@ +var cmd=require('node-cmd'); + +cmd.run('node '+ __dirname + '/unixServer.js'); +cmd.run('node '+ __dirname + '/unixServerSync.js'); + +cmd.run('node '+ __dirname + '/udp4Server.js'); +cmd.run('node '+ __dirname + '/udp6Server.js'); + +cmd.run('node '+ __dirname + '/tcpServer.js'); +cmd.run('node '+ __dirname + '/tcpServerSync.js'); + +cmd.run('node '+ __dirname + '/unixClient.js'); +cmd.run('node '+ __dirname + '/unixClient.js'); + +cmd.run('node '+ __dirname + '/tcpClient.js'); +cmd.run('node '+ __dirname + '/tcpClient.js'); + diff --git a/spec/support/jasmineTest/udp4Server.js b/spec/support/jasmineTest/udp4Server.js index ac89028..7cffa3b 100644 --- a/spec/support/jasmineTest/udp4Server.js +++ b/spec/support/jasmineTest/udp4Server.js @@ -32,7 +32,7 @@ ipc.serveNet( 'message', { id : ipc.config.id, - message : 'I am UDP server!' + message : 'I am UDP4 server!' } ); @@ -40,7 +40,7 @@ ipc.serveNet( } ); - // console.log(ipc.server); + } ); diff --git a/spec/support/jasmineTest/udp6Server.js b/spec/support/jasmineTest/udp6Server.js index 4d76d30..632bd2b 100644 --- a/spec/support/jasmineTest/udp6Server.js +++ b/spec/support/jasmineTest/udp6Server.js @@ -15,11 +15,11 @@ var ipc=require('../../../node-ipc'); * ***************************************/ -ipc.config.id = 'udpServer'; +ipc.config.id = 'udp6Server'; ipc.config.retry= 1500; - ipc.serveNet( + '::1', 'udp6', function(){ @@ -32,7 +32,7 @@ ipc.serveNet( 'message', { id : ipc.config.id, - message : 'I am UDP server!' + message : 'I am UDP6 server!' } ); diff --git a/spec/support/jasmineTest/unixServerSync.js b/spec/support/jasmineTest/unixServerSync.js new file mode 100644 index 0000000..b83f633 --- /dev/null +++ b/spec/support/jasmineTest/unixServerSync.js @@ -0,0 +1,36 @@ +var ipc=require('../../../node-ipc'); + +/***************************************\ + * + * You should start both hello and world + * then you will see them communicating. + * + * *************************************/ + +ipc.config.id = 'unixServerSync'; +ipc.config.retry= 1500; + +ipc.serve( + function(){ + ipc.server.on( + 'message', + function(data,socket){ + setTimeout( + function(){ + ipc.server.emit( + socket, + 'message', + { + id : ipc.config.id, + message : 'Response from unix server' + } + ); + },900 + ); + } + ); + } +); + + +ipc.server.start();