Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -235,22 +235,30 @@ void testURLSessionTaskCommon(
task.toString(); // Just verify that there is no crash.
});

test('cancel', () {
task.cancel();
if (suspendedAfterCancel) {
expect(
task.state,
NSURLSessionTaskState.NSURLSessionTaskStateSuspended,
);
} else {
expect(
task.state,
NSURLSessionTaskState.NSURLSessionTaskStateCanceling,
);
}
expect(task.response, null);
task.toString(); // Just verify that there is no crash.
});
test(
'cancel',
() {
task.cancel();
if (suspendedAfterCancel) {
expect(
task.state,
NSURLSessionTaskState.NSURLSessionTaskStateSuspended,
);
} else {
expect(
task.state,
NSURLSessionTaskState.NSURLSessionTaskStateCanceling,
);
}
expect(task.response, null);
task.toString(); // Just verify that there is no crash.
},
// After the request cancellation is complete, the task state will be
// `NSURLSessionTaskStateCompleted`. So run the test a few times to allow
Copy link
Member

Choose a reason for hiding this comment

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

Why do we care about testing this specific behavior if it's so hard to observe it in usage? Should we allow the completed case as a successful test?

        expect(
          task.state,
          anyOf(
            NSURLSessionTaskState.NSURLSessionTaskStateSuspended,
            NSURLSessionTaskState.NSURLSessionTaskStateCompleted,
          ),
        );

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why do we care about testing this specific behavior if it's so hard to observe it in usage?

At some point my .toString() would throw for certain states so I created a test to catch that. But it might not be worth it.

Should we allow the completed case as a successful test?

        expect(
          task.state,
          anyOf(
            NSURLSessionTaskState.NSURLSessionTaskStateSuspended,
            NSURLSessionTaskState.NSURLSessionTaskStateCompleted,
          ),
        );

That would work but it would miss the intent of the test i.e. to verify that a cancelled test is actually cancelled instead of running to completion (and to verify that toString works correctly ;-))

// the timing to work out (which still isn't a great approach but I can't
// think of a better way).
retry: 5,
);

test('completed', () async {
task.resume();
Expand Down
Loading