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,
emit : emit,
log : log,
retriesRemaining:0
retriesRemaining:config.maxRetries||0
}
new pubsub(client);
@ -78,15 +78,19 @@ function connect(){
client.socket.on(
'close',
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.maxRetries){
client.log(client.config.id.variable,'exceeded connection rety amount of'.warn,client.config.stopRetrying, " or stopRetrying flag set.");
client.socket.destroy();
client=undefined;
return;
}
if(client.config.stopRetrying || client.retriesRemaining<1){
client.log(
client.config.id.variable,
'exceeded connection rety amount of'.warn,
" or stopRetrying flag set."
);
client.socket.destroy();
client=undefined;
return;
}
client.isRetrying=true;

View file

@ -4,7 +4,8 @@ var ipc = require('../node-ipc'),
tests = {},
testCount=0,
fails=[],
passes=[];
passes=[],
debug=true;
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 PASS/FAIL COUNT\n\n####################################\n\n'.data,(passes.length+' ').good,(fails.length+' ').warn,'\n\n');
process.exit(0);
if(!debug)
process.exit(0);
}

View file

@ -3,7 +3,7 @@ var ipc = require('../../../node-ipc'),
server=server[server.length-1]
ipc.config.id = server+'-client';
ipc.config.maxRetries=1;
ipc.config.maxRetries=50;
ipc.connectTo(
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 = ipc.config.id[ipc.config.id.length-1]
@ -10,68 +11,74 @@ ipc.connectTo(
ipc.of.testHarness.on(
'connect',
function(){
console.log(ipc.of)
ipc.of.testHarness.emit(
'start.test',
{
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();