Skip to content

Commit

Permalink
remove enableWorkerThreads
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Apr 27, 2020
1 parent efd33cc commit e330ded
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 43 deletions.
6 changes: 0 additions & 6 deletions packages/jest-worker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ export function hello(param) {

Node 10 shipped with [worker-threads](https://nodejs.org/api/worker_threads.html), a "threading API" that uses SharedArrayBuffers to communicate between the main process and its child threads. This experimental Node feature can significantly improve the communication time between parent and child processes in `jest-worker`.

Since `worker_threads` are considered experimental in Node, you have to opt-in to this behavior by passing `enableWorkerThreads: true` when instantiating the worker. While the feature was unflagged in Node 11.7.0, you'll need to run the Node process with the `--experimental-worker` flag for Node 10.

## API

The only exposed method is a constructor (`JestWorker`) that is initialized by passing the worker path, plus an options object.
Expand Down Expand Up @@ -89,10 +87,6 @@ Provide a custom worker pool to be used for spawning child processes. By default

The arguments that will be passed to the `setup` method during initialization.

#### `enableWorkerThreads: boolean` (optional)

`jest-worker` will automatically detect if `worker_threads` are available, but will not use them unless passed `enableWorkerThreads: true`.

## JestWorker

### Methods
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-worker/src/WorkerPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class WorkerPool extends BaseWorkerPool implements WorkerPoolInterface {

createWorker(workerOptions: WorkerOptions): WorkerInterface {
let Worker;
if (this._options.enableWorkerThreads && canUseWorkerThreads()) {
if (canUseWorkerThreads()) {
Worker = require('./workers/NodeThreadsWorker').default;
} else {
Worker = require('./workers/ChildProcessWorker').default;
Expand Down
29 changes: 0 additions & 29 deletions packages/jest-worker/src/__tests__/WorkerPool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ describe('WorkerPool', () => {
it('should create a NodeThreadWorker and send to it', () => {
jest.mock('worker_threads', () => 'Defined');
const workerPool = new WorkerPool('/path', {
enableWorkerThreads: true,
forkOptions: {},
maxRetries: 1,
numWorkers: 1,
Expand All @@ -102,32 +101,4 @@ describe('WorkerPool', () => {
onEnd,
);
});

it('should avoid NodeThreadWorker if not passed enableWorkerThreads', () => {
jest.mock('worker_threads', () => 'Defined');
const workerPool = new WorkerPool('/path', {
forkOptions: {},
maxRetries: 1,
numWorkers: 1,
workerId: 0,
workerPath: '/path',
});

const onStart = () => {};
const onEnd = () => {};
workerPool.send(0, {foo: 'bar'}, onStart, onEnd);

expect(ChildProcessWorker).toBeCalledWith({
forkOptions: {},
maxRetries: 1,
workerId: 0,
workerPath: '/path',
});
expect(NodeThreadWorker).not.toBeCalled();
expect(workerPool._workers[0].send).toBeCalledWith(
{foo: 'bar'},
onStart,
onEnd,
);
});
});
4 changes: 0 additions & 4 deletions packages/jest-worker/src/__tests__/thread-integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ describe('Jest Worker Process Integration', () => {

it('calls a single method from the worker', async () => {
const farm = new Farm('/tmp/baz.js', {
enableWorkerThreads: true,
exposedMethods: ['foo', 'bar'],
numWorkers: 4,
});
Expand All @@ -80,7 +79,6 @@ describe('Jest Worker Process Integration', () => {

it('distributes sequential calls across child processes', async () => {
const farm = new Farm('/tmp/baz.js', {
enableWorkerThreads: true,
exposedMethods: ['foo', 'bar'],
numWorkers: 4,
});
Expand All @@ -102,7 +100,6 @@ describe('Jest Worker Process Integration', () => {

it('distributes concurrent calls across child processes', async () => {
const farm = new Farm('/tmp/baz.js', {
enableWorkerThreads: true,
exposedMethods: ['foo', 'bar'],
numWorkers: 4,
});
Expand Down Expand Up @@ -131,7 +128,6 @@ describe('Jest Worker Process Integration', () => {
it('sticks parallel calls to children', async () => {
const farm = new Farm('/tmp/baz.js', {
computeWorkerKey: () => '1234567890abcdef',
enableWorkerThreads: true,
exposedMethods: ['foo', 'bar'],
numWorkers: 4,
});
Expand Down
1 change: 0 additions & 1 deletion packages/jest-worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export default class JestWorker {
this._ending = false;

const workerPoolOptions: WorkerPoolOptions = {
enableWorkerThreads: this._options.enableWorkerThreads || false,
forkOptions: this._options.forkOptions || {},
maxRetries: this._options.maxRetries || 3,
numWorkers: this._options.numWorkers || Math.max(cpus().length - 1, 1),
Expand Down
2 changes: 0 additions & 2 deletions packages/jest-worker/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,13 @@ export type FarmOptions = {
workerPath: string,
options?: WorkerPoolOptions,
) => WorkerPoolInterface;
enableWorkerThreads?: boolean;
};

export type WorkerPoolOptions = {
setupArgs: Array<unknown>;
forkOptions: ForkOptions;
maxRetries: number;
numWorkers: number;
enableWorkerThreads: boolean;
};

export type WorkerOptions = {
Expand Down

0 comments on commit e330ded

Please sign in to comment.