fixed #22 and added test under unixSocketTesting
This commit is contained in:
parent
0a58f61224
commit
111cb81dde
4 changed files with 97 additions and 70 deletions
|
@ -9,7 +9,7 @@ function init(config,log){
|
||||||
connect : connect,
|
connect : connect,
|
||||||
emit : emit,
|
emit : emit,
|
||||||
log : log,
|
log : log,
|
||||||
retriesRemaining:0
|
retriesRemaining:config.maxRetries||0
|
||||||
}
|
}
|
||||||
new pubsub(client);
|
new pubsub(client);
|
||||||
|
|
||||||
|
@ -78,15 +78,19 @@ function connect(){
|
||||||
client.socket.on(
|
client.socket.on(
|
||||||
'close',
|
'close',
|
||||||
function(){
|
function(){
|
||||||
client.log('connection closed'.notice ,client.id.variable , client.path.variable);
|
client.log('connection closed'.notice ,client.id.variable , client.path.variable, client.retriesRemaining+' of '+client.config.maxRetries);
|
||||||
|
|
||||||
if(client.stopRetrying || client.retriesRemaining<1){
|
if(client.config.stopRetrying || client.retriesRemaining<1){
|
||||||
if(client.config.maxRetries){
|
client.log(
|
||||||
client.log(client.config.id.variable,'exceeded connection rety amount of'.warn,client.config.stopRetrying, " or stopRetrying flag set.");
|
client.config.id.variable,
|
||||||
client.socket.destroy();
|
'exceeded connection rety amount of'.warn,
|
||||||
client=undefined;
|
" or stopRetrying flag set."
|
||||||
return;
|
);
|
||||||
}
|
|
||||||
|
client.socket.destroy();
|
||||||
|
client=undefined;
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
client.isRetrying=true;
|
client.isRetrying=true;
|
||||||
|
|
|
@ -4,7 +4,8 @@ var ipc = require('../node-ipc'),
|
||||||
tests = {},
|
tests = {},
|
||||||
testCount=0,
|
testCount=0,
|
||||||
fails=[],
|
fails=[],
|
||||||
passes=[];
|
passes=[],
|
||||||
|
debug=true;
|
||||||
|
|
||||||
ipc.config.id = 'testHarness';
|
ipc.config.id = 'testHarness';
|
||||||
|
|
||||||
|
@ -161,5 +162,6 @@ function checkComplete(){
|
||||||
ipc.log('####################################\n\n FAILS\n\n####################################\n\n'.warn,fails.join('\n').warn,'\n\n');
|
ipc.log('####################################\n\n FAILS\n\n####################################\n\n'.warn,fails.join('\n').warn,'\n\n');
|
||||||
ipc.log('####################################\n\n PASS/FAIL COUNT\n\n####################################\n\n'.data,(passes.length+' ').good,(fails.length+' ').warn,'\n\n');
|
ipc.log('####################################\n\n PASS/FAIL COUNT\n\n####################################\n\n'.data,(passes.length+' ').good,(fails.length+' ').warn,'\n\n');
|
||||||
|
|
||||||
process.exit(0);
|
if(!debug)
|
||||||
|
process.exit(0);
|
||||||
}
|
}
|
|
@ -3,7 +3,7 @@ var ipc = require('../../../node-ipc'),
|
||||||
server=server[server.length-1]
|
server=server[server.length-1]
|
||||||
|
|
||||||
ipc.config.id = server+'-client';
|
ipc.config.id = server+'-client';
|
||||||
ipc.config.maxRetries=1;
|
ipc.config.maxRetries=50;
|
||||||
|
|
||||||
ipc.connectTo(
|
ipc.connectTo(
|
||||||
server,
|
server,
|
||||||
|
@ -18,7 +18,21 @@ ipc.connectTo(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
process.exit();
|
//wait to ensure above event has opportunity to tranfer and register client properly
|
||||||
|
setTimeout(
|
||||||
|
function(){
|
||||||
|
ipc.disconnect(server);
|
||||||
|
},
|
||||||
|
100
|
||||||
|
);
|
||||||
|
|
||||||
|
//wait long enough that the test will fail if disconnect does not happen
|
||||||
|
setTimeout(
|
||||||
|
function(){
|
||||||
|
process.exit(0);
|
||||||
|
},
|
||||||
|
2000
|
||||||
|
)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
var ipc = require('../../../node-ipc');
|
var ipc = require('../../../node-ipc'),
|
||||||
|
expectedClient=ipc.config.id+'-client';
|
||||||
|
|
||||||
ipc.config.id = __dirname.split('/');
|
ipc.config.id = __dirname.split('/');
|
||||||
ipc.config.id = ipc.config.id[ipc.config.id.length-1]
|
ipc.config.id = ipc.config.id[ipc.config.id.length-1]
|
||||||
|
@ -10,68 +11,74 @@ ipc.connectTo(
|
||||||
ipc.of.testHarness.on(
|
ipc.of.testHarness.on(
|
||||||
'connect',
|
'connect',
|
||||||
function(){
|
function(){
|
||||||
console.log(ipc.of)
|
|
||||||
ipc.of.testHarness.emit(
|
ipc.of.testHarness.emit(
|
||||||
'start.test',
|
'start.test',
|
||||||
{
|
{
|
||||||
id : ipc.config.id,
|
id : ipc.config.id,
|
||||||
duration: 2000
|
duration: 1200
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
ipc.serve(
|
|
||||||
function(){
|
|
||||||
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
ipc.server.on(
|
|
||||||
'connect',
|
|
||||||
function(){
|
|
||||||
ipc.of.testHarness.emit(
|
|
||||||
'pass',
|
|
||||||
'unix-server-connection'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
ipc.server.on(
|
|
||||||
'socket.disconnected',
|
|
||||||
function(socket,id){
|
|
||||||
var test='unix-server-detected-correct-id-disconnection';
|
|
||||||
if(id==ipc.config.id+'-client'){
|
|
||||||
ipc.of.testHarness.emit(
|
|
||||||
'pass',
|
|
||||||
test
|
|
||||||
);
|
|
||||||
}else{
|
|
||||||
ipc.of.testHarness.emit(
|
|
||||||
'fail',
|
|
||||||
test
|
|
||||||
);
|
|
||||||
}
|
|
||||||
ipc.of.testHarness.emit(
|
|
||||||
'end.test'
|
|
||||||
);
|
|
||||||
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
ipc.server.on(
|
|
||||||
'test-test',
|
|
||||||
function(data,socket){
|
|
||||||
ipc.of.testHarness.emit(
|
|
||||||
'pass',
|
|
||||||
'unix-client-message'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
ipc.server.define.listen['app.message']='This event type listens for message strings as value of data key.';
|
|
||||||
|
|
||||||
ipc.server.start();
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
ipc.serve(
|
||||||
|
function(){
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
ipc.server.on(
|
||||||
|
'connect',
|
||||||
|
function(){
|
||||||
|
ipc.of.testHarness.emit(
|
||||||
|
'pass',
|
||||||
|
'unix-server-connection'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
ipc.server.on(
|
||||||
|
'socket.disconnected',
|
||||||
|
function(socket,id){
|
||||||
|
var test='unix-server-detected-correct-id-disconnection';
|
||||||
|
if(id==ipc.config.id+'-client'){
|
||||||
|
ipc.of.testHarness.emit(
|
||||||
|
'pass',
|
||||||
|
test
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
ipc.of.testHarness.emit(
|
||||||
|
'fail',
|
||||||
|
test+' : detected wrong id of '+id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
ipc.of.testHarness.emit(
|
||||||
|
'end.test'
|
||||||
|
);
|
||||||
|
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
ipc.server.on(
|
||||||
|
'test-test',
|
||||||
|
function(data,socket){
|
||||||
|
ipc.of.testHarness.emit(
|
||||||
|
'pass',
|
||||||
|
'unix-client-message'
|
||||||
|
);
|
||||||
|
|
||||||
|
if(socket.id==expectedClient){
|
||||||
|
ipc.of.testHarness.emit(
|
||||||
|
'pass',
|
||||||
|
'unix-client-registered with proper id'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
ipc.server.define.listen['app.message']='This event type listens for message strings as value of data key.';
|
||||||
|
|
||||||
|
ipc.server.start();
|
Loading…
Reference in a new issue