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

This commit is contained in:
nileshprasad 2016-01-07 15:55:06 -08:00
parent 4cf5906e95
commit cef306eb4b
17 changed files with 739 additions and 860 deletions

View file

@ -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"
]

View file

@ -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');
}
);
}
);
}
);
}
);
}
);

View file

@ -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();
}
);
}
);

View file

@ -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();
}
);
}
);

View file

@ -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
}
);

View file

@ -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();
}
);
}
);

View file

@ -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
}
);

View file

@ -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);
}
);
}
);
}
);
}
);

View file

@ -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();

View file

@ -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();
}
);
}
);

View file

@ -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();

View file

@ -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();
}
);
}
);
}
);
}
);
}
);

View file

@ -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();
}
);
*/
}
);

View file

@ -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');

View file

@ -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);
}
);

View file

@ -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!'
}
);

View file

@ -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();