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

Update CancelableOperation test to not assume completion happens synchronously. #203

Merged
merged 1 commit into from
Mar 9, 2022

Conversation

lrhn
Copy link
Member

@lrhn lrhn commented Mar 4, 2022

A bug in Completer.complete could allow the completion to happen synchronously, even on a non-synchronous completer.
That is being fixed in the SDK.

That affects AsyncMemoizer, which uses a pattern which could trigger the bug.
The CancelableOperation completer uses such a memoizer and that would cause a cancel to trigger .then listeners synchronusly.

With that no longer being the case, two tests needed to insert delays to wait for the cancellation to be propagated to the listner.

@lrhn lrhn requested a review from natebosch March 4, 2022 14:31
@@ -460,8 +460,10 @@ void main() {
var operation = runThen();
var workCompleter = Completer<int>();
originalCompleter.complete(workCompleter.future);
originalCompleter.operation.cancel();
var cancelation = originalCompleter.operation.cancel();
expect(originalCompleter.isCanceled, true);
Copy link
Member

Choose a reason for hiding this comment

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

How does isCanceled become true synchronously here while we had to add the await above?

Copy link
Member Author

Choose a reason for hiding this comment

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

The isCanceled of the operation you cancel gets set immediately.
Then the cancellation propagates asynchronously to .then listeners, which is what the other test checks (operation.isCanceled vs originalCompleter.operation.isCanceled.)

@lrhn lrhn merged commit 8060c71 into master Mar 9, 2022
@natebosch natebosch deleted the fix-tests branch March 30, 2022 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants