node-ipc/spec/support/jasmineTest/unixServerSync.js

61 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-01-10 20:03:05 +11:00
'use strict';
2016-01-10 18:23:40 +11:00
const ipc=require('../../../node-ipc');
const process=require('process');
2016-01-10 18:28:00 +11:00
const dieAfter=30000;
2016-01-10 18:23:40 +11:00
const messageDelay=900;
2016-01-10 18:23:40 +11:00
//die after 60 seconds
setTimeout(
function killServerProcess(){
process.exit(0);
},
dieAfter
);
2016-01-10 18:23:40 +11:00
ipc.config.id = 'unixServerSync';
ipc.config.retry= 1500;
2016-01-10 18:23:40 +11:00
ipc.config.silent=true;
ipc.serve(
2016-01-10 18:23:40 +11:00
function serverStarted(){
2016-01-10 20:03:05 +11:00
let ready=false;
let messageDelay=500;
ipc.server.on(
'message',
2016-01-10 18:23:40 +11:00
function gotMessage(data,socket){
2016-01-10 20:03:05 +11:00
if(ready){
ipc.server.emit(
socket,
'message',
{
id : ipc.config.id,
message : 'Error, client not wating for server response before sending request.'
}
);
}
ready=true;
setTimeout(
2016-01-10 18:23:40 +11:00
function delayedMessage(){
2016-01-10 20:03:05 +11:00
ready=false;
ipc.server.emit(
socket,
'message',
{
id : ipc.config.id,
message : 'Response from unix server'
}
);
2016-01-10 18:23:40 +11:00
},
messageDelay
);
}
);
}
);
ipc.server.start();