-
Notifications
You must be signed in to change notification settings - Fork 392
test(cupertino_http): Retry cancellation tests. #1858
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
1c8d5e5
8ed4312
a44b87f
a0b4d2b
d63f000
875a4d1
11666a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -213,6 +213,9 @@ void testURLSessionTaskCommon( | |
| await request.drain<void>(); | ||
| request.response.headers.set('Content-Type', 'text/plain'); | ||
| request.response.write('Hello World'); | ||
| // Add a small delay to allow cancellation to run before the request | ||
| // is completed. | ||
| await Future<void>.delayed(const Duration(seconds: 2)); | ||
| await request.response.close(); | ||
| }); | ||
| final session = URLSession.sharedSession(); | ||
|
|
@@ -235,22 +238,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. | ||
| }, | ||
| // If the task completes before cancelling then the task state will be | ||
| // `NSURLSessionTaskStateCompleted`. So run the test a few times to allow | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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,
),
);
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
At some point my
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 |
||
| // 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(); | ||
|
|
||
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.
Is it feasible to coordinate the sequencing without an arbitrary delay? Should we wait on a
Completerhere and have the test body complete it after the cancellation runs? It will require edits in existing tests, but much better to be explicit about the interleaving.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 misunderstood what was going on. I removed the delay and updated the documentation.
What is happening is that that cancel, when complete, transitions to the completed state. And that sometimes happens before we can observe the state as cancelled.
If this doesn't make the test reliable, I should probably just remove it.