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; ipc.config.retry = 600;
describe('TCP Socket verification of client', describe('TCP Socket verification of client',
function(){ function TCPClientSpec(){
it( it(
'Verify retry attempts by TCP client to connect to the server as per the value set in "maxRetries" parameter.', 'Verify retry attempts by TCP client to connect to the server as per the value set in "maxRetries" parameter.',
function(done){ 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.maxRetries = 3;
ipc.config.stopRetrying = false; ipc.config.stopRetrying = false;
//set to -1 because there is an error on the first fail
//before retrying
let errorCount=-1;
ipc.connectToNet( ipc.connectToNet(
'tcpFakeServer', 'tcpFakeServer',
8002, 8002,
function(){ function(){
ipc.of.tcpFakeServer.on(
ipc.of.tcpFakeServer.on( 'error',
'disconnect', function gotError(err){
function(){ errorCount++;
expect(ipc.of.tcpFakeServer.retriesRemaining).toBe(
if(ipc.of.tcpFakeServer.retriesRemaining == 0){ ipc.config.maxRetries-errorCount
);
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--;
} }
); );
} }
); );
setTimeout( setTimeout(
function(){ function testDelay(){
ipc.disconnect('tcpFakeServer'); expect(errorCount).toBe(ipc.config.maxRetries);
done(); ipc.disconnect('tcpFakeServer');
},2500 done();
},
ipc.config.retry*ipc.config.maxRetries +
ipc.config.retry+ipc.config.retry
); );
} }
); );
it( it(
'Verify TCP client does not connect to the TCPserver when "stopRetrying" value is set to true.', 'Verify TCP client does not connect to the TCPserver when "stopRetrying" value is set to true.',
function(done){ function testIt(done){
let tcpRetryAttempt = 3; //variable created to count the attempt made by client to connect to the server.
ipc.config.maxRetries = 3; ipc.config.maxRetries = 3;
ipc.config.stopRetrying = true; 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( ipc.connectToNet(
'tcpFakeServer', 'tcpFakeServer',
8002, 8002,
function(){ function open(){
ipc.of.tcpFakeServer.on( ipc.of.tcpFakeServer.on(
'disconnect', 'error',
function(){ function gotError(err){
expect(ipc.of.tcpFakeServer.retriesRemaining).toBe(ipc.config.maxRetries);
if(ipc.of.tcpFakeServer.retriesRemaining == 3){ errorCount++;
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--;
} }
); );
} }
); );
setTimeout( setTimeout(
function(){ function testDelay(){
ipc.disconnect('tcpFakeServer'); expect(errorCount).toBe(0);
done(); expect(ipc.of.tcpFakeServer.retriesRemaining).toBe(ipc.config.maxRetries);
},700 ipc.disconnect('tcpFakeServer');
done();
},
ipc.config.retry*ipc.config.maxRetries
); );
} }
); );
it( it(
'Verify TCP client connects to server named "tcpServer" and receives message.', 'Verify TCP client connects to server named "tcpServer" and receives message.',
function(done){ function testIt(done){
ipc.connectToNet( ipc.connectToNet(
'tcpServer', 'tcpServer',
8300, 8300,
function(){ function open(){
ipc.of.tcpServer.on( ipc.of.tcpServer.on(
'connect', '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( ipc.of.tcpServer.emit(
'message', 'message',
@ -133,78 +109,24 @@ describe('TCP Socket verification of client',
message : 'Hello from testClient.' message : 'Hello from testClient.'
} }
); );
}
);
ipc.of.tcpServer.on( ipc.of.tcpServer.on(
'message', 'error',
function(data,socket){ function testError(err){
expect(err).toBe(false);
expect(data.id).toBe('tcpServer'); testDone();
expect(data.message).toBe('I am TCP server!');
ipc.disconnect('tcpServer');
done();
}
);
} }
); );
} }
); );
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; ipc.config.retry = 1000;
describe('TCP Socket verification of server', describe('TCP Socket verification of server',
function(){ function TCPSocketSpec(){
it(
it(
'Verify TCP server detects only 1 client out of 2 clients and receives message.', 'Verify TCP server detects only 1 client out of 2 clients and receives message.',
function(done){ function(done){
@ -44,5 +43,5 @@ describe('TCP Socket verification of server',
} }
); );
} }
); );

View file

@ -4,7 +4,7 @@ const ipc = require('../../../../node-ipc');
describe( describe(
'UDP Socket verification.', 'UDP Socket verification.',
function testDescription(){ function UDPSocketSpec(){
it( it(
'Verify UDP server of type udp4 connects to UDP server named "udp4Server" and receives message.', 'Verify UDP server of type udp4 connects to UDP server named "udp4Server" and receives message.',
function testIt(done){ function testIt(done){
@ -29,7 +29,7 @@ describe(
ipc.server.on( ipc.server.on(
'error', 'error',
function(err){ function gotErr(err){
expect(err).toBe(false); expect(err).toBe(false);
testDone(); testDone();
} }
@ -71,7 +71,7 @@ describe(
'::1', '::1',
clientPort, clientPort,
'udp6', 'udp6',
function(){ function serverStarted(){
ipc.server.on( ipc.server.on(
'message', 'message',
function(data,socket){ function(data,socket){
@ -83,7 +83,7 @@ describe(
ipc.server.on( ipc.server.on(
'error', 'error',
function(err){ function gotErr(err){
expect(err).toBe(false); expect(err).toBe(false);
testDone(); testDone();
} }

View file

@ -6,7 +6,7 @@ ipc.config.id ='testClient';
ipc.config.retry = 600; ipc.config.retry = 600;
describe('Test Cases for Unix client: ', describe('Test Cases for Unix client: ',
function describeTests(){ function UnixClientSpec(){
it( it(
'Verify retry attempts by Unix client to connect to the Unix server as per the value set in "maxRetries" parameter.', 'Verify retry attempts by Unix client to connect to the Unix server as per the value set in "maxRetries" parameter.',
function testIt(done){ function testIt(done){
@ -46,7 +46,7 @@ describe('Test Cases for Unix client: ',
it( it(
'Verify Unix client does not connect to the unix server when "stopRetrying" value is set to true.', '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.maxRetries = 3;
ipc.config.stopRetrying = true; ipc.config.stopRetrying = true;
@ -104,7 +104,7 @@ describe('Test Cases for Unix client: ',
ipc.of.unixServer.on( ipc.of.unixServer.on(
'error', 'error',
function(err){ function gotErr(err){
expect(err).toBe(false); expect(err).toBe(false);
testDone(); testDone();
} }
@ -156,7 +156,7 @@ describe('Test Cases for Unix client: ',
ipc.of.unixServerSync.on( ipc.of.unixServerSync.on(
'message', 'message',
function(data){ function gotMessage(data){
expect(data.message).toBe('Response from unix server'); expect(data.message).toBe('Response from unix server');
responseCounter++; responseCounter++;