-
Notifications
You must be signed in to change notification settings - Fork 1
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
Mock URLSession Behavior for Testing #11
Conversation
let behaviors = defaultRequestBehaviors + requestBehaviors | ||
|
||
let urlRequest = makeFinalizedRequest(fromOriginalRequest: request.urlRequest, behaviors: behaviors) | ||
let dataTask = makeDataTask(forURLRequest: urlRequest, successHTTPStatusCodes: request.successHTTPStatusCodes, completion: completion) | ||
let dataTask = makeDataTask(forURLRequest: urlRequest, behaviors: behaviors, successHTTPStatusCodes: request.successHTTPStatusCodes, completion: completion) |
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.
Our test caught this bug that must've been around for a while. This change ensures that the behaviors’ requestDidFinish
will get called, whereas before, it was not 😱
@@ -101,7 +101,7 @@ extension NetworkController: NetworkRequestPerformer { | |||
|
|||
public func send(_ request: any NetworkRequest, requestBehaviors: [RequestBehavior]) async throws -> NetworkResponse { | |||
try await withCheckedThrowingContinuation { continuation in | |||
send(request) { result in | |||
send(request, requestBehaviors: requestBehaviors) { result in |
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.
Similarly, for our new async/await API, we weren’t passing along behaviors.
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.
Looks good, one super minor comment
Co-authored-by: Brian Capps <[email protected]>
Co-authored by @ashlirankin18
What it Does
Follow-up to #6
In #6 it was proposed that we’d test out the functionality, but timing-wise it didn’t make sense, so we’ve added some basic tests today.
And good news, the tests caught two bugs!
We decided to minimally mock
URLSession
andURLSessionDataTask
with protocol conformances. This unfortunately changes some types in public APIs, but hopefully that's deemed worth it for the future of test writing in these libraries.Additionally, strictly for time constraints, we only mocked the non-
Combine
URLSession
method as we only intended to test the new async/await public API during this working session.How I Tested
Notes
See GitHub comments in the code below on the bug fixes caught by tests.
Screenshot
N/A