-
Notifications
You must be signed in to change notification settings - Fork 934
Fix racy promises in SpecTestRunner #2693
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty much LGTM.
I'm not a huge fan of the exception you're making for step.applyClientState?.primary
. It seems arbitrary. What consequences would there be for not making this exception?
This multi-tab limbo documents test test fails if we don't make the exception. If we fully drain the queue after |
@@ -219,6 +222,11 @@ export class AsyncQueue { | |||
return this._isShuttingDown; | |||
} | |||
|
|||
// Visible for testing | |||
isEmpty(): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to make this private or remove it entirely.
// It should still be possible to drain the queue after it is shutting down. | ||
return this.enqueueEvenAfterShutdown(() => Promise.resolve()); | ||
async drain(): Promise<void> { | ||
// Operations in the queue prior to draining may have enqueued additional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this works, but if it does you could get rid of all size accounting:
let currentTail : Promise<void>;
do (
currentTail = this.tail;
await currentTail;
} while (currentTail !== this.tail);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use do/while loop + new comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Context: An update to
tslib
(link) changed the promise resolution order. We previously had multiple race conditions in the SpecTestRunner that happened to resolve in the correct order, but now break. Although we drain the AsyncQueue after each step, operations scheduled onto the AQ as part of the step run after thedrain()
call with thetslib
update, as opposed to running beforedrain()
previously.This PR makes the
SpecTestRunner
drain until the AQ is empty, which ensures that theSpecTestRunner
is in a consistent state before moving onto the next step.