diff --git a/node-ipc.js b/node-ipc.js index 61ae0b6..5c4c9d7 100644 --- a/node-ipc.js +++ b/node-ipc.js @@ -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){ diff --git a/testHarness/readme.md b/testHarness/readme.md index 202bffa..fe2c214 100644 --- a/testHarness/readme.md +++ b/testHarness/readme.md @@ -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. diff --git a/testHarness/tests/tcp-socket-test/client.js b/testHarness/tests/tcp-socket-test/client.js new file mode 100644 index 0000000..c67fa2d --- /dev/null +++ b/testHarness/tests/tcp-socket-test/client.js @@ -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 + ) + } + ); + } +); \ No newline at end of file diff --git a/testHarness/tests/tcp-socket-test/server.js b/testHarness/tests/tcp-socket-test/server.js new file mode 100644 index 0000000..fe6fdab --- /dev/null +++ b/testHarness/tests/tcp-socket-test/server.js @@ -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(); \ No newline at end of file