2016-01-10 23:32:46 +11:00
|
|
|
/*global describe, expect, it*/
|
2016-01-10 20:03:05 +11:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const ipc = require('../../../../node-ipc');
|
|
|
|
|
2016-01-10 18:23:40 +11:00
|
|
|
ipc.config.id ='testClient';
|
|
|
|
ipc.config.retry = 600;
|
2016-01-08 10:55:06 +11:00
|
|
|
|
|
|
|
describe('Test Cases for Unix client: ',
|
2016-01-10 22:02:36 +11:00
|
|
|
function UnixClientSpec(){
|
2016-01-10 20:03:05 +11:00
|
|
|
it(
|
|
|
|
'Verify retry attempts by Unix client to connect to the Unix server as per the value set in "maxRetries" parameter.',
|
|
|
|
function testIt(done){
|
|
|
|
|
|
|
|
ipc.config.maxRetries = 3;
|
|
|
|
|
|
|
|
//set to -1 because there is an error on the first fail
|
|
|
|
//before retrying
|
|
|
|
let errorCount=-1;
|
|
|
|
|
|
|
|
ipc.connectTo(
|
|
|
|
'fakeworld',
|
|
|
|
function open(){
|
|
|
|
ipc.of.fakeworld.on(
|
|
|
|
'error',
|
|
|
|
function gotError(err){
|
|
|
|
errorCount++;
|
|
|
|
expect(ipc.of.fakeworld.retriesRemaining).toBe(
|
|
|
|
ipc.config.maxRetries-errorCount
|
|
|
|
);
|
2016-01-10 23:37:52 +11:00
|
|
|
expect(err).toBeDefined();
|
2016-01-10 20:03:05 +11:00
|
|
|
}
|
|
|
|
);
|
2016-01-10 20:14:54 +11:00
|
|
|
}
|
2016-01-10 20:03:05 +11:00
|
|
|
);
|
|
|
|
|
|
|
|
setTimeout(
|
|
|
|
function testDelay(){
|
|
|
|
expect(errorCount).toBe(ipc.config.maxRetries);
|
|
|
|
ipc.disconnect('fakeworld');
|
|
|
|
done();
|
|
|
|
},
|
|
|
|
ipc.config.retry*ipc.config.maxRetries +
|
|
|
|
ipc.config.retry+ipc.config.retry
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
it(
|
|
|
|
'Verify Unix client does not connect to the unix server when "stopRetrying" value is set to true.',
|
2016-01-10 22:02:36 +11:00
|
|
|
function testIt(done){
|
2016-01-10 20:03:05 +11:00
|
|
|
|
|
|
|
ipc.config.maxRetries = 3;
|
|
|
|
ipc.config.stopRetrying = true;
|
|
|
|
ipc.silent=true;
|
|
|
|
|
|
|
|
//set to -1 because there is an error on the first fail
|
|
|
|
//before retrying
|
|
|
|
let errorCount=-1;
|
|
|
|
|
|
|
|
ipc.connectTo(
|
|
|
|
'fakeworld',
|
|
|
|
function open(){
|
|
|
|
|
|
|
|
ipc.of.fakeworld.on(
|
|
|
|
'error',
|
|
|
|
function gotError(err){
|
|
|
|
expect(ipc.of.fakeworld.retriesRemaining).toBe(ipc.config.maxRetries);
|
|
|
|
errorCount++;
|
2016-01-10 23:37:52 +11:00
|
|
|
expect(err).toBeDefined();
|
2016-01-10 20:03:05 +11:00
|
|
|
}
|
|
|
|
);
|
2016-01-10 20:14:54 +11:00
|
|
|
}
|
2016-01-10 20:03:05 +11:00
|
|
|
);
|
|
|
|
|
|
|
|
setTimeout(
|
|
|
|
function testDelay(){
|
|
|
|
expect(errorCount).toBe(0);
|
|
|
|
expect(ipc.of.fakeworld.retriesRemaining).toBe(ipc.config.maxRetries);
|
|
|
|
ipc.disconnect('fakeworld');
|
|
|
|
done();
|
|
|
|
},
|
|
|
|
ipc.config.retry*ipc.config.maxRetries
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
it(
|
|
|
|
'Verify unix client connects to "unixServer" and receives message.',
|
|
|
|
function testIt(done){
|
|
|
|
ipc.connectTo(
|
|
|
|
'unixServer',
|
|
|
|
'/tmp/app.unixServer',
|
|
|
|
function open(){
|
|
|
|
ipc.of.unixServer.on(
|
|
|
|
'connect',
|
|
|
|
function connected(){
|
|
|
|
ipc.of.unixServer.on(
|
|
|
|
'message',
|
2016-01-10 23:57:08 +11:00
|
|
|
function gotMessage(data){
|
2016-01-10 20:03:05 +11:00
|
|
|
expect(data.id).toBe('unixServer');
|
|
|
|
expect(data.message).toBe('I am unix server!');
|
|
|
|
testDone();
|
2016-01-08 10:55:06 +11:00
|
|
|
}
|
2016-01-10 20:03:05 +11:00
|
|
|
);
|
2016-01-08 10:55:06 +11:00
|
|
|
|
2016-01-10 20:03:05 +11:00
|
|
|
ipc.of.unixServer.on(
|
|
|
|
'error',
|
2016-01-10 22:02:36 +11:00
|
|
|
function gotErr(err){
|
2016-01-10 20:03:05 +11:00
|
|
|
expect(err).toBe(false);
|
|
|
|
testDone();
|
2016-01-08 10:55:06 +11:00
|
|
|
}
|
2016-01-10 20:03:05 +11:00
|
|
|
);
|
|
|
|
|
|
|
|
ipc.of.unixServer.emit(
|
|
|
|
'message',
|
|
|
|
{
|
|
|
|
id : ipc.config.id,
|
|
|
|
message : 'Hello from Client.'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
function testDone(){
|
|
|
|
ipc.disconnect('unixServer');
|
|
|
|
done();
|
2016-01-08 10:55:06 +11:00
|
|
|
}
|
2016-01-10 20:03:05 +11:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
it(
|
|
|
|
'Verify unix client queues the requests being sent to the server synchronously until it receives the response from server.',
|
|
|
|
function testIt(done){
|
|
|
|
|
|
|
|
ipc.config.sync = true;
|
|
|
|
let responseCounter = 0;
|
|
|
|
|
|
|
|
ipc.connectTo(
|
|
|
|
'unixServerSync',
|
|
|
|
'/tmp/app.unixServerSync',
|
|
|
|
function open(){
|
|
|
|
ipc.of.unixServerSync.on(
|
|
|
|
'connect',
|
|
|
|
function connected(){
|
|
|
|
|
|
|
|
for(let i=0; i<5; i++){
|
|
|
|
ipc.of.unixServerSync.emit(
|
2016-01-08 10:55:06 +11:00
|
|
|
'message',
|
|
|
|
{
|
|
|
|
id : ipc.config.id,
|
2016-01-10 20:03:05 +11:00
|
|
|
message : 'Unix Client Request '
|
2016-01-08 10:55:06 +11:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2016-01-10 20:03:05 +11:00
|
|
|
|
|
|
|
ipc.of.unixServerSync.on(
|
|
|
|
'message',
|
2016-01-10 22:02:36 +11:00
|
|
|
function gotMessage(data){
|
2016-01-10 20:03:05 +11:00
|
|
|
expect(data.message).toBe('Response from unix server');
|
|
|
|
responseCounter++;
|
|
|
|
|
|
|
|
if (responseCounter < 5){
|
|
|
|
return;
|
2016-01-08 10:55:06 +11:00
|
|
|
}
|
2016-01-10 20:03:05 +11:00
|
|
|
expect(responseCounter).toBe(5);
|
|
|
|
testDone();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
ipc.of.unixServerSync.on(
|
|
|
|
'error',
|
|
|
|
function testError(err){
|
|
|
|
expect(err).toBe(false);
|
|
|
|
testDone();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
function testDone(){
|
|
|
|
ipc.disconnect('unixServerSync');
|
|
|
|
done();
|
2016-01-08 10:55:06 +11:00
|
|
|
}
|
2016-01-10 20:03:05 +11:00
|
|
|
}
|
2016-01-08 10:55:06 +11:00
|
|
|
);
|
2016-01-10 20:03:05 +11:00
|
|
|
}
|
2016-01-08 10:55:06 +11:00
|
|
|
);
|