Skip to content

Commit

Permalink
fix #155: reuse subprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
1999 committed Jul 28, 2018
1 parent 7bdaca8 commit 949a845
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 32 deletions.
1 change: 1 addition & 0 deletions src/main/mocha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default class MochaWrapper extends Mocha {

setMaxParallel(maxParallel: number) {
this.maxParallel = maxParallel;
return this;
}

enableExitMode() {
Expand Down
32 changes: 0 additions & 32 deletions test/delay/reporter.js

This file was deleted.

1 change: 1 addition & 0 deletions test/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ test 'TESTCASE: --retries and --bail should work well together' test/bail-and-re
test 'TESTCASE: subprocess exits before sending an end message' test/no-subprocess-end/index.js
test 'TESTCASE: unhandled rejections should not force subprocess to exit' test/q-promises/index.js
test 'TESTCASE: uncaught exceptions should not force subprocess to exit' test/uncaught-exception/index.js
test 'TESTCASE: subprocess reusage' test/subprocess-reuse/index.js

echo "Passes: $PASSES Failes: $FAILES"
echo ""
Expand Down
1 change: 1 addition & 0 deletions test/subprocess-reuse/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
counter.json
1 change: 1 addition & 0 deletions test/subprocess-reuse/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Check that subprocesses are reused
32 changes: 32 additions & 0 deletions test/subprocess-reuse/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env node

const assert = require('assert');
const { writeFileSync } = require('fs');
const { resolve } = require('path');
const MochaParallelTests = require('../../dist/main/mocha').default;

const counterFilePath = resolve(__dirname, 'counter.json');
const reporterPath = resolve(__dirname, '../util/silent-reporter.js');

process.on('unhandledRejection', (reason) => {
console.error(reason.stack);
process.exit(1);
});

// initialize counter file
writeFileSync(counterFilePath, '[]');

const mocha = new MochaParallelTests();
mocha
.reporter(reporterPath)
.addFile(`${__dirname}/spec/1.spec.js`)
.addFile(`${__dirname}/spec/2.spec.js`)
.addFile(`${__dirname}/spec/3.spec.js`)
.addFile(`${__dirname}/spec/4.spec.js`)
.slow(5000)
.setMaxParallel(2)
.run()
.on('end', function () {
const pidsUsed = require(counterFilePath);
assert.strictEqual(pidsUsed.length, 2, `Number of processes is wrong: ${pidsUsed.length}`);
});
17 changes: 17 additions & 0 deletions test/subprocess-reuse/spec/1.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { writeFileSync } = require('fs');
const { resolve } = require('path');

const updateCounterWithOwnPid = () => {
const counterFilePath = resolve(__dirname, '../counter.json');
const pids = new Set(require(counterFilePath));

pids.add(process.pid);
writeFileSync(counterFilePath, JSON.stringify([...pids]));
};

describe('suite', () => {
it('case', (done) => {
updateCounterWithOwnPid();
setTimeout(done, 1000);
});
});
17 changes: 17 additions & 0 deletions test/subprocess-reuse/spec/2.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { writeFileSync } = require('fs');
const { resolve } = require('path');

const updateCounterWithOwnPid = () => {
const counterFilePath = resolve(__dirname, '../counter.json');
const pids = new Set(require(counterFilePath));

pids.add(process.pid);
writeFileSync(counterFilePath, JSON.stringify([...pids]));
};

describe('suite', () => {
it('case', (done) => {
updateCounterWithOwnPid();
setTimeout(done, 1000);
});
});
17 changes: 17 additions & 0 deletions test/subprocess-reuse/spec/3.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { writeFileSync } = require('fs');
const { resolve } = require('path');

const updateCounterWithOwnPid = () => {
const counterFilePath = resolve(__dirname, '../counter.json');
const pids = new Set(require(counterFilePath));

pids.add(process.pid);
writeFileSync(counterFilePath, JSON.stringify([...pids]));
};

describe('suite', () => {
it('case', (done) => {
updateCounterWithOwnPid();
setTimeout(done, 1000);
});
});
17 changes: 17 additions & 0 deletions test/subprocess-reuse/spec/4.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { writeFileSync } = require('fs');
const { resolve } = require('path');

const updateCounterWithOwnPid = () => {
const counterFilePath = resolve(__dirname, '../counter.json');
const pids = new Set(require(counterFilePath));

pids.add(process.pid);
writeFileSync(counterFilePath, JSON.stringify([...pids]));
};

describe('suite', () => {
it('case', (done) => {
updateCounterWithOwnPid();
setTimeout(done, 1000);
});
});

0 comments on commit 949a845

Please sign in to comment.