fixed #22 and added test under unixSocketTesting

This commit is contained in:
Brandon Nozaki Miller 2014-09-04 22:06:25 -07:00
parent 0a58f61224
commit 111cb81dde
4 changed files with 97 additions and 70 deletions

View file

@ -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,16 +78,20 @@ 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.config.stopRetrying || client.retriesRemaining<1){
client.log(
client.config.id.variable,
'exceeded connection rety amount of'.warn,
" or stopRetrying flag set."
);
if(client.stopRetrying || client.retriesRemaining<1){
if(client.config.maxRetries){
client.log(client.config.id.variable,'exceeded connection rety amount of'.warn,client.config.stopRetrying, " or stopRetrying flag set.");
client.socket.destroy(); client.socket.destroy();
client=undefined; client=undefined;
return; return;
} }
}
client.isRetrying=true; client.isRetrying=true;

View file

@ -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');
if(!debug)
process.exit(0); process.exit(0);
} }

View file

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

View file

@ -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,12 +11,15 @@ 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
}
);
}
)
} }
); );
@ -47,7 +51,7 @@ ipc.connectTo(
}else{ }else{
ipc.of.testHarness.emit( ipc.of.testHarness.emit(
'fail', 'fail',
test test+' : detected wrong id of '+id
); );
} }
ipc.of.testHarness.emit( ipc.of.testHarness.emit(
@ -65,13 +69,16 @@ ipc.connectTo(
'pass', 'pass',
'unix-client-message' '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.define.listen['app.message']='This event type listens for message strings as value of data key.';
ipc.server.start(); ipc.server.start();
}
)
}
);