Update PR feedback, add more tests
This commit is contained in:
parent
3c54e1f8a5
commit
864c8d6aed
@ -196,7 +196,15 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@param cancelPendingTasks Whether or not to cancel pending tasks.
|
||||
*/
|
||||
- (void)invalidateSessionCancelingTasks:(BOOL)cancelPendingTasks;
|
||||
- (void)invalidateSessionCancelingTasks:(BOOL)cancelPendingTasks DEPRECATED_ATTRIBUTE;
|
||||
|
||||
/**
|
||||
Invalidates the managed session, optionally canceling pending tasks and optionally resets given session.
|
||||
|
||||
@param cancelPendingTasks Whether or not to cancel pending tasks.
|
||||
@param resetSession Whether or not to reset the session of the manager.
|
||||
*/
|
||||
- (void)invalidateSessionCancelingTasks:(BOOL)cancelPendingTasks resetSession:(BOOL)resetSession;
|
||||
|
||||
///-------------------------
|
||||
/// @name Running Data Tasks
|
||||
|
||||
@ -404,7 +404,8 @@ static NSString * const AFNSURLSessionTaskDidSuspendNotification = @"com.alamofi
|
||||
7) If the current class implementation of `resume` is not equal to the super class implementation of `resume` AND the current implementation of `resume` is not equal to the original implementation of `af_resume`, THEN swizzle the methods
|
||||
8) Set the current class to the super class, and repeat steps 3-8
|
||||
*/
|
||||
NSURLSession * session = [NSURLSession sharedSession];
|
||||
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration];
|
||||
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wnonnull"
|
||||
NSURLSessionDataTask *localDataTask = [session dataTaskWithURL:nil];
|
||||
@ -424,6 +425,7 @@ static NSString * const AFNSURLSessionTaskDidSuspendNotification = @"com.alamofi
|
||||
}
|
||||
|
||||
[localDataTask cancel];
|
||||
[session finishTasksAndInvalidate];
|
||||
}
|
||||
}
|
||||
|
||||
@ -724,12 +726,18 @@ static NSString * const AFNSURLSessionTaskDidSuspendNotification = @"com.alamofi
|
||||
#pragma mark -
|
||||
|
||||
- (void)invalidateSessionCancelingTasks:(BOOL)cancelPendingTasks {
|
||||
[self invalidateSessionCancelingTasks:cancelPendingTasks resetSession:NO];
|
||||
}
|
||||
|
||||
- (void)invalidateSessionCancelingTasks:(BOOL)cancelPendingTasks resetSession:(BOOL)resetSession {
|
||||
if (cancelPendingTasks) {
|
||||
[self.session invalidateAndCancel];
|
||||
} else {
|
||||
[self.session finishTasksAndInvalidate];
|
||||
}
|
||||
self.session = nil;
|
||||
if (resetSession) {
|
||||
self.session = nil;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@ -70,10 +70,10 @@
|
||||
- (void)tearDown {
|
||||
[super tearDown];
|
||||
[self.localManager.session.configuration.URLCache removeAllCachedResponses];
|
||||
[self.localManager invalidateSessionCancelingTasks:YES];
|
||||
[self.localManager invalidateSessionCancelingTasks:YES resetSession:YES];
|
||||
self.localManager = nil;
|
||||
|
||||
[self.backgroundManager invalidateSessionCancelingTasks:YES];
|
||||
[self.backgroundManager invalidateSessionCancelingTasks:YES resetSession:YES];
|
||||
self.backgroundManager = nil;
|
||||
}
|
||||
|
||||
@ -158,11 +158,19 @@
|
||||
[self waitForExpectationsWithCommonTimeout];
|
||||
}
|
||||
|
||||
- (void)testSessionIsStillValid {
|
||||
|
||||
NSURLSession *session = self.localManager.session;
|
||||
[self.localManager invalidateSessionCancelingTasks:YES resetSession:NO];
|
||||
|
||||
XCTAssertEqual(session, self.localManager.session);
|
||||
}
|
||||
|
||||
- (void)testSessionRecreatesAgain {
|
||||
|
||||
[self.localManager setValue:nil forKey:@"session"];
|
||||
[self.localManager invalidateSessionCancelingTasks:YES resetSession:NO];
|
||||
|
||||
XCTAssertNotNil([self.localManager valueForKey:@"session"]);
|
||||
XCTAssertNotNil(self.localManager.session);
|
||||
}
|
||||
|
||||
- (void)testUploadTaskDoesReportProgress {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user