-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jest-worker): fix hanging when child process workers are killed
- Loading branch information
Showing
4 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/jest-worker/src/workers/__tests__/__fixtures__/SelfKillWorker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* 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. | ||
*/ | ||
const {isMainThread} = require('worker_threads'); | ||
|
||
async function selfKill() { | ||
// This test is intended for the child process worker. If the Node.js worker | ||
// thread mode is accidentally tested instead, let's prevent a confusing | ||
// situation where process.kill stops the Jest test harness itself. | ||
if (!isMainThread) { | ||
// process.exit is documented to only stop the current thread rather than | ||
// the process in a worker_threads environment. | ||
process.exit(); | ||
} | ||
|
||
process.kill(process.pid); | ||
} | ||
|
||
module.exports = { | ||
selfKill, | ||
}; |