added TCP client tests back in

This commit is contained in:
Brandon Nozaki Miller 2016-01-10 03:02:36 -08:00
parent b3b99482e1
commit f0056a7d1f
4 changed files with 79 additions and 158 deletions

View File

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

View File

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

View File

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

View File

@ -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++;