fixed #24 and added test of tcp-socket-test to test the basic functions of tcp socket
This commit is contained in:
parent
2765c700dc
commit
a29f414540
4 changed files with 125 additions and 1 deletions
|
@ -66,7 +66,7 @@ function disconnect(id){
|
|||
if(!ipc.of[id])
|
||||
return;
|
||||
|
||||
ipc.of[id].stopRetrying=true;
|
||||
ipc.of[id].config.stopRetrying=true;
|
||||
|
||||
ipc.of[id].off('*');
|
||||
if(ipc.of[id].socket){
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#node-ipc test harness
|
||||
***TestHarness was intended to be run on linux.***
|
||||
*the test.js file is intended to start and run all of the files in the test folder*
|
||||
|
||||
A full regression test should be done before each release to npm to insure that no expected or previously documented bugs pop up again.
|
||||
|
|
39
testHarness/tests/tcp-socket-test/client.js
Normal file
39
testHarness/tests/tcp-socket-test/client.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
var ipc=require('../../../node-ipc'),
|
||||
server=__dirname.split('/'),
|
||||
server=server[server.length-1]
|
||||
|
||||
ipc.config.id = server+'-client';
|
||||
ipc.config.maxRetries=50;
|
||||
|
||||
ipc.connectToNet(
|
||||
server,
|
||||
function(){
|
||||
ipc.of[server].on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.of[server].emit(
|
||||
'test-test',
|
||||
{
|
||||
id:ipc.config.id
|
||||
}
|
||||
);
|
||||
|
||||
//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
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
84
testHarness/tests/tcp-socket-test/server.js
Normal file
84
testHarness/tests/tcp-socket-test/server.js
Normal file
|
@ -0,0 +1,84 @@
|
|||
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]
|
||||
ipc.config.maxRetries=1;
|
||||
|
||||
ipc.connectTo(
|
||||
'testHarness',
|
||||
function(){
|
||||
ipc.of.testHarness.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.of.testHarness.emit(
|
||||
'start.test',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
duration: 1200
|
||||
}
|
||||
);
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
ipc.serveNet(
|
||||
function(){
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.of.testHarness.emit(
|
||||
'pass',
|
||||
'tcp-server-connection'
|
||||
);
|
||||
}
|
||||
)
|
||||
|
||||
ipc.server.on(
|
||||
'socket.disconnected',
|
||||
function(socket,id){
|
||||
var test='tcp-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',
|
||||
'tcp-client-message'
|
||||
);
|
||||
|
||||
if(socket.id==expectedClient){
|
||||
ipc.of.testHarness.emit(
|
||||
'pass',
|
||||
'tcp-client-registered with proper id'
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.define.listen.message='This event type listens for message strings as value of data key.';
|
||||
|
||||
ipc.server.start();
|
Loading…
Reference in a new issue