Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Feb 23, 2024
1 parent ff80f7e commit 8524d23
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion fixtures/slave.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var app = http.createServer(function (req, res) {
return res.end(process.env.CFORK_ENV_TEST);
}
if (req.url === '/worker_index') {
return res.end(`worker index: ${process.env.CFORK_WORKER_INDEX}`);
return res.end(`slave worker index: ${process.env.CFORK_SLAVE_WORKER_INDEX}, ${process.env.CFORK_SLAVE_WORKER_COUNT}`);
}
res.end(req.method + ' ' + req.url);
}).listen(port);
Expand Down
2 changes: 1 addition & 1 deletion fixtures/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var app = http.createServer(function (req, res) {
return res.end(process.env.CFORK_ENV_TEST);
}
if (req.url === '/worker_index') {
return res.end(`worker index: ${process.env.CFORK_WORKER_INDEX}`);
return res.end(`worker index: ${process.env.CFORK_WORKER_INDEX}, ${process.env.CFORK_WORKER_COUNT}`);
}
res.end(req.method + ' ' + req.url);
}).listen(port);
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function fork(options) {
});

for (var i = 0; i < count; i++) {
const env = { CFORK_WORKER_INDEX: String(i) };
const env = { CFORK_WORKER_INDEX: String(i), CFORK_WORKER_COUNT: count };
newWorker = forkWorker(null, env);
newWorker._clusterSettings = cluster.settings;
newWorker._clusterWorkerEnv = env;
Expand All @@ -181,7 +181,7 @@ function fork(options) {
slaves.map(normalizeSlaveConfig)
.forEach(function(settings, index) {
if (settings) {
const env = { CFORK_WORKER_INDEX: String(count + index) };
const env = { CFORK_SLAVE_WORKER_INDEX: String(index), CFORK_SLAVE_WORKER_COUNT: slaves.length };
newWorker = forkWorker(settings, env);
newWorker._clusterSettings = settings;
newWorker._clusterWorkerEnv = env;
Expand Down
8 changes: 4 additions & 4 deletions test/cfork.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('test/cfork.test.js', () => {
resp.statusCode.should.equal(200);
urllib.request('http://localhost:1985/worker_index', function (err, body, resp) {
should.ifError(err);
body.toString().should.equal('worker index: 4');
body.toString().should.equal('slave worker index: 0, 1');
resp.statusCode.should.equal(200);
done();
});
Expand All @@ -107,13 +107,13 @@ describe('test/cfork.test.js', () => {
should.ifError(err);
const text = body.toString();
// console.log('%o', text);
assert(text === 'worker index: 0' || text === 'worker index: 1'
|| text === 'worker index: 2' || text === 'worker index: 3', text);
assert(text === 'worker index: 0, 4' || text === 'worker index: 1, 4'
|| text === 'worker index: 2, 4 ' || text === 'worker index: 3, 4', text);
resp.statusCode.should.equal(200);
urllib.request('http://localhost:1985/worker_index', function (err, body, resp) {
should.ifError(err);
const text = body.toString();
assert.equal(text, 'worker index: 4');
assert.equal(text, 'slave worker index: 0, 1');
resp.statusCode.should.equal(200);
done();
});
Expand Down

0 comments on commit 8524d23

Please sign in to comment.