think-cluster
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -81,2 +81,3 @@ const cluster = require('cluster'); | ||
setTimeout(function () { | ||
if(!worker.isConnected()) return; | ||
worker.process.kill('SIGINT'); | ||
@@ -83,0 +84,0 @@ }, 100); |
{ | ||
"name": "think-cluster", | ||
"description": "Cluster manage for ThinkJS", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "welefen", |
@@ -37,3 +37,96 @@ const test = require('ava'); | ||
test.serial('normal case', async t => { | ||
// test.serial('normal case', async t => { | ||
// try { | ||
// let result = {}; | ||
// let options = { | ||
// workers: 1 | ||
// }; | ||
// executeProcess('master.js', options,'forkWorkers', (output) => { | ||
// Object.assign(result, output); | ||
// }); | ||
// await sleep(interval); | ||
// t.is(result.isForked, true); | ||
// t.is(result.options.workers, 1); | ||
// } catch (e) { | ||
// } | ||
// }); | ||
// | ||
// test.serial('options.workers >= 2 && enableAgent is true', async t => { | ||
// try { | ||
// let result = {}; | ||
// let options = { | ||
// workers: 2, | ||
// reloadSignal: 'SIGUSR2', | ||
// enableAgent: true | ||
// }; | ||
// executeProcess('master.js', options,'forkWorkers', (output) => { | ||
// Object.assign(result, output); | ||
// }); | ||
// await sleep(interval); | ||
// t.is(result.isForked, true); | ||
// t.is(result.options.enableAgent, true); | ||
// } catch (e) { | ||
// } | ||
// }); | ||
// | ||
// test.serial('if options.workers < 2,enableAgent is false', async t => { | ||
// try { | ||
// let result = {}; | ||
// let options = { | ||
// workers: 1, | ||
// reloadSignal: 'SIGUSR2', | ||
// enableAgent: true | ||
// }; | ||
// executeProcess('master.js', options,'forkWorkers', (output) => { | ||
// Object.assign(result, output); | ||
// }); | ||
// await sleep(interval); | ||
// t.is(result.isForked, true); | ||
// // if workers < 2, set enableAgent false | ||
// t.is(result.options.enableAgent, false); | ||
// } catch (e) { | ||
// } | ||
// }); | ||
// | ||
// test.serial('reloadWorkers', async t => { | ||
// try { | ||
// let result = {}; | ||
// executeProcess('master.js', {workers:4}, 'reloadWorkers', (output) => { | ||
// Object.assign(result, output); | ||
// }); | ||
// await sleep(interval * 2); | ||
// console.log(result); | ||
// t.notDeepEqual(result.beforeWorkers, result.afterWorkers); | ||
// } catch (e) { | ||
// } | ||
// }); | ||
// | ||
// test.serial('trigger SIGUSR2 signal', async t => { | ||
// try { | ||
// let result = {}; | ||
// let options = { | ||
// reloadSignal: 'SIGUSR2', | ||
// }; | ||
// let masterProcess = executeProcess('master.js', options,'forkWorkers', (output) => { | ||
// Object.assign(result, output); | ||
// }); | ||
// await sleep(interval); | ||
// t.is(result.isForked, true); | ||
// console.log(`master process id is ${masterProcess.pid}`); | ||
// await sleep(interval); | ||
// | ||
// exec(`KILL -SIGUSR2 ${masterProcess.pid}`,{shell:'/bin/sh'},(error, stdout, stderr)=>{ | ||
// console.log(`stdout: ${stdout}`); | ||
// console.log(`stderr: ${stderr}`); | ||
// if (error !== null) { | ||
// console.log(`exec error: ${error}`); | ||
// } | ||
// }); | ||
// await sleep(interval); | ||
// | ||
// } catch (e) { | ||
// } | ||
// }); | ||
test.serial('trigger worker unHandleRejection ', async t => { | ||
try { | ||
@@ -44,8 +137,8 @@ let result = {}; | ||
}; | ||
executeProcess('master.js', options,'forkWorkers', (output) => { | ||
executeProcess('worker.js', options,'unHandleRejection', (output) => { | ||
Object.assign(result, output); | ||
console.log(result); | ||
}); | ||
await sleep(interval); | ||
t.is(result.isForked, true); | ||
t.is(result.options.workers, 1); | ||
t.is(result.message.indexOf('onUnhandledRejection') != -1, true); | ||
} catch (e) { | ||
@@ -55,78 +148,16 @@ } | ||
test.serial('options.workers >= 2 && enableAgent is true', async t => { | ||
test.serial('trigger worker unCaughtException', async t => { | ||
try { | ||
let result = {}; | ||
let options = { | ||
workers: 2, | ||
reloadSignal: 'SIGUSR2', | ||
enableAgent: true | ||
workers: 1 | ||
}; | ||
executeProcess('master.js', options,'forkWorkers', (output) => { | ||
executeProcess('worker.js', options,'unCaughtException', (output) => { | ||
Object.assign(result, output); | ||
console.log(result); | ||
}); | ||
await sleep(interval); | ||
t.is(result.isForked, true); | ||
t.is(result.options.enableAgent, true); | ||
t.is(result.message.indexOf('onUncaughtException') != -1, true); | ||
} catch (e) { | ||
} | ||
}); | ||
test.serial('if options.workers < 2,enableAgent is false', async t => { | ||
try { | ||
let result = {}; | ||
let options = { | ||
workers: 1, | ||
reloadSignal: 'SIGUSR2', | ||
enableAgent: true | ||
}; | ||
executeProcess('master.js', options,'forkWorkers', (output) => { | ||
Object.assign(result, output); | ||
}); | ||
await sleep(interval); | ||
t.is(result.isForked, true); | ||
// if workers < 2, set enableAgent false | ||
t.is(result.options.enableAgent, false); | ||
} catch (e) { | ||
} | ||
}); | ||
test.serial('reloadWorkers', async t => { | ||
try { | ||
let result = {}; | ||
executeProcess('master.js',{},'reloadWorkers',(output)=>{ | ||
Object.assign(result, output); | ||
}); | ||
await sleep(interval*2); | ||
console.log(result); | ||
t.notDeepEqual(result.beforeWorkers,result.afterWorkers); | ||
} catch (e) { | ||
} | ||
}); | ||
test.serial('trigger SIGUSR2 signal', async t => { | ||
try { | ||
let result = {}; | ||
let options = { | ||
reloadSignal: 'SIGUSR2', | ||
}; | ||
let masterProcess = executeProcess('master.js', options,'forkWorkers', (output) => { | ||
Object.assign(result, output); | ||
}); | ||
await sleep(interval*2); | ||
t.is(result.isForked, true); | ||
console.log(`master process id is ${masterProcess.pid}`); | ||
exec(`KILL -SIGUSR2 ${masterProcess.pid}`,{shell:'/bin/sh'},(error, stdout, stderr)=>{ | ||
console.log(`stdout: ${stdout}`); | ||
console.log(`stderr: ${stderr}`); | ||
if (error !== null) { | ||
console.log(`exec error: ${error}`); | ||
} | ||
}); | ||
await sleep(interval); | ||
} catch (e) { | ||
} | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33556
18
1124
10