Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

think-cluster

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

think-cluster - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

test/script/worker.js

1

lib/master.js

@@ -81,2 +81,3 @@ const cluster = require('cluster');

setTimeout(function () {
if(!worker.isConnected()) return;
worker.process.kill('SIGINT');

@@ -83,0 +84,0 @@ }, 100);

2

package.json
{
"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) {
}
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc