Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: worker being killed after being spawned and other worker bugs #13107

Merged
merged 53 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
71d0080
test: ad integration test case for worker not executing test
phawxby Aug 8, 2022
8c6ab73
test: add test case for worker being killed just once
phawxby Aug 9, 2022
86acdf1
fix: worker being killed after spawning
phawxby Aug 9, 2022
718425b
Merge branch 'master' into worker-restart-bug
phawxby Aug 9, 2022
de0c0e8
fix: missing license
phawxby Aug 9, 2022
d83aa84
fix: flaky tests
phawxby Aug 9, 2022
9435d0b
chore: add some diagnostic logging
phawxby Aug 9, 2022
29e1193
chore: break apart tests to see where the problem is occuring
phawxby Aug 9, 2022
c23f581
fix: handling of work ready status
phawxby Aug 9, 2022
e8a8058
chore: add fallback timeout
phawxby Aug 9, 2022
4e0b399
refactor: add abstract class with common functions and vars
phawxby Aug 9, 2022
790f772
fix: restarting on init
phawxby Aug 9, 2022
b4151ea
refactor: event emitting is a much cleaner way of tracking what's goi…
phawxby Aug 9, 2022
2753069
chore: better handle shutdown events
phawxby Aug 9, 2022
617e102
fix: only set out of memory when necessary
phawxby Aug 9, 2022
28230da
chore: windows debugging
phawxby Aug 9, 2022
60b5b1b
chore: try and debug single test
phawxby Aug 9, 2022
a9a3779
chore: remove debugging
phawxby Aug 9, 2022
cdf9627
chore: remove logging
phawxby Aug 9, 2022
7a79c92
chore: simplify tests and move more to abstract worker
phawxby Aug 9, 2022
11fd6f8
chore: only run flaky test
phawxby Aug 10, 2022
55f4097
chore: enable tests again
phawxby Aug 10, 2022
723951b
fix: missing snapshot
phawxby Aug 10, 2022
a062850
chore: try to resolve the flake
phawxby Aug 10, 2022
66c83bd
chore: logging
phawxby Aug 10, 2022
c47404d
chore: see if this changes debugging output
phawxby Aug 10, 2022
9331bd2
chore: make noisy
phawxby Aug 10, 2022
5058e14
chore: debugging
phawxby Aug 10, 2022
ddbfb5e
chore: more
phawxby Aug 10, 2022
811e228
chore: even more robust logging
phawxby Aug 10, 2022
197c0da
chore: refactor error streaming monitoring
phawxby Aug 10, 2022
0d0d03e
chore: error handling
phawxby Aug 10, 2022
11e8b25
chore: log this
phawxby Aug 10, 2022
8f427a4
fix: tests and try to detect process crashes differently on windows
phawxby Aug 10, 2022
57d3b20
chore: remove debug logging
phawxby Aug 10, 2022
d3abe14
chore: remove only
phawxby Aug 10, 2022
f704620
chore: add win32 specific logic to try and work around the issue
phawxby Aug 10, 2022
5a840bb
chore: back to adding debug logging
phawxby Aug 10, 2022
d6b2db0
chore: try adding more possible detections
phawxby Aug 10, 2022
202323b
chore: try a different event
phawxby Aug 10, 2022
9e7d081
chore: disconnect handling
phawxby Aug 10, 2022
75037d2
fix: test bug
phawxby Aug 10, 2022
37c5a43
chore: log child and buffer
phawxby Aug 10, 2022
3e8b3ae
chore: forgot to make public
phawxby Aug 10, 2022
fab410a
chore: log
phawxby Aug 10, 2022
8e4a31e
chore: use up memory quicker and more logging
phawxby Aug 10, 2022
b974eea
chore: try removing force exit to see if that helps with the confusin…
phawxby Aug 10, 2022
1e1023d
chore: different strat
phawxby Aug 10, 2022
ab2931d
chore: remove debugging
phawxby Aug 10, 2022
c610bdb
chore: revert to silent worker
phawxby Aug 11, 2022
ee20013
Update CHANGELOG.md
SimenB Aug 11, 2022
bd786b1
chore: pr feedback
phawxby Aug 11, 2022
613fcf2
chore: pr changes
phawxby Aug 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- `[jest-config]` [**BREAKING**] Make `snapshotFormat` default to `escapeString: false` and `printBasicPrototype: false` ([#13036](https://github.com/facebook/jest/pull/13036))
- `[jest-environment-jsdom]` [**BREAKING**] Upgrade to `jsdom@20` ([#13037](https://github.com/facebook/jest/pull/13037), [#13058](https://github.com/facebook/jest/pull/13058))
- `[jest-worker]` Adds `workerIdleMemoryLimit` option which is used as a check for worker memory leaks >= Node 16.11.0 and recycles child workers as required. ([#13056](https://github.com/facebook/jest/pull/13056), [#13105](https://github.com/facebook/jest/pull/13105), [#13106](https://github.com/facebook/jest/pull/13106))
- `[jest-worker]` Adds `workerIdleMemoryLimit` option which is used as a check for worker memory leaks >= Node 16.11.0 and recycles child workers as required. ([#13056](https://github.com/facebook/jest/pull/13056), [#13105](https://github.com/facebook/jest/pull/13105), [#13106](https://github.com/facebook/jest/pull/13106), [#13107](https://github.com/facebook/jest/pull/13107))
- `[pretty-format]` [**BREAKING**] Remove `ConvertAnsi` plugin in favour of `jest-serializer-ansi-escapes` ([#13040](https://github.com/facebook/jest/pull/13040))

### Fixes
Expand Down
9 changes: 9 additions & 0 deletions e2e/__tests__/__snapshots__/workerRestarting.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`all 3 test files should complete 1`] = `
"Test Suites: 3 passed, 3 total
Tests: 3 passed, 3 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites."
`;
16 changes: 16 additions & 0 deletions e2e/__tests__/workerRestarting.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import {extractSummary} from '../Utils';
import runJest from '../runJest';

it('all 3 test files should complete', () => {
const result = runJest('worker-restarting');
expect(result.exitCode).toBe(0);
const {summary} = extractSummary(result.stderr);
expect(summary).toMatchSnapshot();
});
10 changes: 10 additions & 0 deletions e2e/worker-restarting/__tests__/test1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

test('basic test', () => {
expect(true).toBeTruthy();
});
10 changes: 10 additions & 0 deletions e2e/worker-restarting/__tests__/test2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

test('basic test', () => {
expect(true).toBeTruthy();
});
10 changes: 10 additions & 0 deletions e2e/worker-restarting/__tests__/test3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

test('basic test', () => {
expect(true).toBeTruthy();
});
6 changes: 6 additions & 0 deletions e2e/worker-restarting/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
SimenB marked this conversation as resolved.
Show resolved Hide resolved
"jest": {
"maxWorkers": 2,
"workerIdleMemoryLimit": "1MB"
}
}
32 changes: 32 additions & 0 deletions packages/jest-worker/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,15 @@ export interface WorkerPoolInterface {
}

export interface WorkerInterface {
get state(): WorkerStates;

send(
request: ChildMessage,
onProcessStart: OnStart,
onProcessEnd: OnEnd,
onCustomMessage: OnCustomMessage,
): void;

waitForExit(): Promise<void>;
forceExit(): void;

Expand All @@ -83,6 +86,18 @@ export interface WorkerInterface {
*/
getWorkerSystemId(): number;
getMemoryUsage(): Promise<number | null>;
/**
* Checks to see if the child worker is actually running.
*/
isWorkerRunning(): boolean;
/**
* When the worker child is started and ready to start handling requests.
*
* @remarks
* This mostly exists to help with testing so that you don't check the status
* of things like isWorkerRunning before it actually is.
*/
waitForWorkerReady(): Promise<void>;
}

export type PoolExitResult = {
Expand Down Expand Up @@ -170,8 +185,21 @@ export type WorkerOptions = {
* the raw output of the worker.
*/
silent?: boolean;
/**
* Used to immediately bind event handlers.
*/
on?: {
[WorkerEvents.STATE_CHANGE]:
| OnStateChangeHandler
| ReadonlyArray<OnStateChangeHandler>;
};
};

export type OnStateChangeHandler = (
state: WorkerStates,
oldState: WorkerStates,
) => void;

// Messages passed from the parent to the children.

export type MessagePort = typeof EventEmitter & {
Expand Down Expand Up @@ -265,3 +293,7 @@ export enum WorkerStates {
SHUTTING_DOWN = 'shutting-down',
SHUT_DOWN = 'shut-down',
}

export enum WorkerEvents {
STATE_CHANGE = 'state-change',
}
Loading