node-ipc/test/TCP/server.js
2021-07-02 14:53:41 -07:00

71 lines
No EOL
1.3 KiB
JavaScript

import VanillaTest from 'vanilla-test';
import Is from 'strong-type';
import {IPCModule} from '../../node-ipc.js';
import delay from '../../helpers/delay.js';
async function run(){
const test=new VanillaTest;
const is=new Is;
const cleanup=function(){
test.pass();
test.done();
}
const fail=function(err){
console.trace(err)
test.fail();
}
var transmit_delay = 1000;
try{
test.expects(
'Server to detect TCP client connection.'
);
const ipc=new IPCModule;
ipc.config.id ='testWorld';
ipc.config.retry = 1000;
ipc.config.networkPort=8500;
let clientCounter=0;
ipc.serveNet(
function serverStarted(){
ipc.server.on(
'connect',
function connected(socket){
clientCounter++;
ipc.emit(socket,'END');
}
);
}
);
ipc.server.start();
await delay(transmit_delay*3);
ipc.server.stop();
console.log(clientCounter,1)
test.compare(clientCounter,1);
}catch(err){
fail(err);
}
cleanup();
}
export {
run as default,
run
}