Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

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

Merged
merged 1 commit into from
Mar 9, 2022

Conversation

lrhn
Copy link
Contributor

@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
Contributor

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
Contributor 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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants