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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions test/cancelable_operation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,12 @@ void main() {
});

group('original operation canceled', () {
test('onCancel not set', () {
test('onCancel not set', () async {
onCancel = null;

final operation = runThen();

expect(originalCompleter.operation.cancel(), completes);
await expectLater(originalCompleter.operation.cancel(), completes);
expect(operation.isCanceled, true);
});

Expand Down Expand Up @@ -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.)

workCompleter.complete(0);
await cancelation;
expect(operation.isCanceled, true);
await workCompleter.future;
});
Expand Down