added TCP client tests back in
This commit is contained in:
parent
b3b99482e1
commit
f0056a7d1f
4 changed files with 79 additions and 158 deletions
|
@ -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');
|
||||
}
|
||||
function gotError(err){
|
||||
errorCount++;
|
||||
expect(ipc.of.tcpFakeServer.retriesRemaining).toBe(
|
||||
ipc.config.maxRetries-errorCount
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
tcpRetryAttempt--;
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
setTimeout(
|
||||
function(){
|
||||
function testDelay(){
|
||||
expect(errorCount).toBe(ipc.config.maxRetries);
|
||||
ipc.disconnect('tcpFakeServer');
|
||||
done();
|
||||
},2500
|
||||
},
|
||||
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);
|
||||
|
||||
|
||||
function open(){
|
||||
ipc.of.tcpFakeServer.on(
|
||||
'error',
|
||||
function(err){
|
||||
console.log('Error is: ', err);
|
||||
ipc.disconnect('tcpFakeServer');
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
tcpRetryAttempt--;
|
||||
function gotError(err){
|
||||
expect(ipc.of.tcpFakeServer.retriesRemaining).toBe(ipc.config.maxRetries);
|
||||
errorCount++;
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
setTimeout(
|
||||
function(){
|
||||
function testDelay(){
|
||||
expect(errorCount).toBe(0);
|
||||
expect(ipc.of.tcpFakeServer.retriesRemaining).toBe(ipc.config.maxRetries);
|
||||
ipc.disconnect('tcpFakeServer');
|
||||
done();
|
||||
},700
|
||||
},
|
||||
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,77 +109,23 @@ describe('TCP Socket verification of client',
|
|||
message : 'Hello from testClient.'
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.of.tcpServer.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
'error',
|
||||
function testError(err){
|
||||
expect(err).toBe(false);
|
||||
testDone();
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
expect(data.id).toBe('tcpServer');
|
||||
expect(data.message).toBe('I am TCP server!');
|
||||
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');
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -6,8 +6,7 @@ ipc.config.id ='testWorld';
|
|||
ipc.config.retry = 1000;
|
||||
|
||||
describe('TCP Socket verification of server',
|
||||
function(){
|
||||
|
||||
function TCPSocketSpec(){
|
||||
it(
|
||||
'Verify TCP server detects only 1 client out of 2 clients and receives message.',
|
||||
function(done){
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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++;
|
||||
|
||||
|
|
Loading…
Reference in a new issue