Skip to content

Conversation

@mjesun
Copy link
Contributor

@mjesun mjesun commented Feb 19, 2019

Nodes in a linked list were shared among all lists for each worker; which is not what we would like to do. The expected part to be shared is only the request object (which uses the first position as a lock between jobs); but the wrapper object for the linked list needs to be unique.

I also added a test that would crash without the fix.

}

private _enqueue(task: QueueChildMessage, workerId: number): Farm {
const item = {task, next: null};
Copy link
Contributor Author

@mjesun mjesun Feb 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core of the fix is only this line; where instead of pushing to all queues the task object, we create one specifically for each queue, (meaning that when doing .next in the tail of a linked list, we don't affect all others).

The rest of the PR are "cosmetic" changes, and the test.

@mjesun mjesun requested a review from rubennorte February 19, 2019 14:31
}

lock(workerId: number): void {
private _lock(workerId: number): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically breaking, but I guess these shouldn't be called anyways by consumers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, playing with worker locks is a recipe for disaster :D

- `[jest-validate]` Fix validating async functions ([#7894](https://github.com/facebook/jest/issues/7894))
- `[jest-circus]` Fix bug with test.only ([#7888](https://github.com/facebook/jest/pull/7888))
- `[jest-transform]` Normalize config and remove unecessary checks, convert `TestUtils.js` to TypeScript ([#7801](https://github.com/facebook/jest/pull/7801)
- `[jest-transform]` Normalize config and remove unecessary checks, convert `TestUtils.js` to TypeScript ([#7801](https://github.com/facebook/jest/pull/7801))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

took me forever to spot the fixed missing paren :P

@mjesun mjesun merged commit 7cc0771 into jestjs:master Feb 19, 2019
private _numOfWorkers: number;
private _offset: number;
private _queue: Array<QueueChildMessage | null>;
private _queue: Array<QueueItem | null>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private _queue: Array<QueueItem | null>;
private _queue: Array<QueueItem>;

right? there can never be nulls in the queue now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The queue can be empty, and that's signaled by a null item.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so Array<QueueItem> | [null]? I guess it doesn't matter in practice

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The array index refers to each of the workers (I.e. this._queue.length is numOfWorkers, not the list of jobs); so each item in the array is either the first element of the linked list, or null.

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants