mirror of
https://github.com/google/gtm-session-fetcher
synced 2026-11-09 22:25:56 +05:45
This reverts commit 7f0723149c.
Seeing some of our (Google's) tests fail because of the change in flow, holding
off on this change until the change in behavior can be better
documented/understood. This might end up needing to be a breaking change if the
behavior difference on tests is enough.
This commit is contained in:
1 parent
f9ba439b06
commit
6634e84db6
2 files changed
+2
-50
No files matched your search
@@ -977,13 +977,7 @@ NSString *const kGTMSessionFetcherUploadInitialBackoffStartedNotification =
|
||||
[self setDelegateCallbackQueue:self.callbackQueue];
|
||||
self.completionHandler = handler;
|
||||
|
||||
#if GTM_DISABLE_FETCHER_TEST_BLOCK
|
||||
BOOL hasTestBlock = NO;
|
||||
#else
|
||||
BOOL hasTestBlock = (self.testBlock != nil);
|
||||
#endif
|
||||
|
||||
if ([self isRestartedUpload] && !hasTestBlock) {
|
||||
if ([self isRestartedUpload]) {
|
||||
// When restarting an upload, we know the destination location for chunk fetches,
|
||||
// but we need to query to find the initial offset.
|
||||
if (![self isPaused]) {
|
||||
@@ -998,17 +992,12 @@ NSString *const kGTMSessionFetcherUploadInitialBackoffStartedNotification =
|
||||
GTMSESSION_ASSERT_DEBUG(self.fetcherInFlight == nil, @"unexpected fetcher in flight: %@",
|
||||
self.fetcherInFlight);
|
||||
|
||||
// Restarted fetchers created by uploadFetcherWithLocation: have no initial
|
||||
// request, but the superclass requires one to invoke testBlock.
|
||||
if (hasTestBlock && self.request == nil && _uploadLocationURL != nil) {
|
||||
[self setRequest:[NSMutableURLRequest requestWithURL:_uploadLocationURL]];
|
||||
}
|
||||
|
||||
self.fetcherInFlight = self;
|
||||
[super beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
|
||||
self.fetcherInFlight = nil;
|
||||
// callback
|
||||
|
||||
BOOL hasTestBlock = (self.testBlock != nil);
|
||||
if (![self isRestartedUpload] && !hasTestBlock) {
|
||||
if (error == nil) {
|
||||
[self beginChunkFetches];
|
||||
@@ -1603,9 +1592,6 @@ NSString *const kGTMSessionFetcherUploadInitialBackoffStartedNotification =
|
||||
// copy other fetcher settings to the new fetcher
|
||||
chunkFetcher.retryEnabled = self.retryEnabled;
|
||||
chunkFetcher.maxRetryInterval = self.maxRetryInterval;
|
||||
#if !GTM_DISABLE_FETCHER_TEST_BLOCK
|
||||
chunkFetcher.testBlock = self.testBlock;
|
||||
#endif
|
||||
|
||||
if ([self isRetryEnabled]) {
|
||||
// We interpose our own retry method both so we can change the request to ask the server to
|
||||
|
||||
@@ -2112,40 +2112,6 @@ static void TestProgressBlock(GTMSessionUploadFetcher *fetcher, int64_t bytesSen
|
||||
XCTAssertEqual(fnctr.uploadLocationObtained, 1);
|
||||
}
|
||||
|
||||
- (void)testRestartedUploadFetcherWithTestBlock {
|
||||
NSURL *uploadLocationURL = [NSURL URLWithString:@"https://example.com/upload_location"];
|
||||
GTMSessionUploadFetcher *fetcher =
|
||||
[GTMSessionUploadFetcher uploadFetcherWithLocation:uploadLocationURL
|
||||
uploadMIMEType:@"text/plain"
|
||||
chunkSize:5000
|
||||
fetcherService:_service];
|
||||
fetcher.useBackgroundSession = NO;
|
||||
|
||||
NSData *fakedResponseData = [@"Upload complete" dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSHTTPURLResponse *fakedResponse =
|
||||
[[NSHTTPURLResponse alloc] initWithURL:uploadLocationURL
|
||||
statusCode:200
|
||||
HTTPVersion:@"HTTP/1.1"
|
||||
headerFields:@{@"Content-Type" : @"text/plain"}];
|
||||
|
||||
__block BOOL testBlockInvoked = NO;
|
||||
fetcher.testBlock =
|
||||
^(GTMSessionFetcher *fetcherToTest, GTMSessionFetcherTestResponse testResponse) {
|
||||
testBlockInvoked = YES;
|
||||
testResponse(fakedResponse, fakedResponseData, nil);
|
||||
};
|
||||
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"completion handler"];
|
||||
[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
|
||||
XCTAssertNil(error);
|
||||
XCTAssertEqualObjects(data, fakedResponseData);
|
||||
[expectation fulfill];
|
||||
}];
|
||||
[self waitForExpectationsWithTimeout:_timeoutInterval handler:nil];
|
||||
XCTAssertTrue(testBlockInvoked);
|
||||
[self assertCallbacksReleasedForFetcher:fetcher];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif // !TARGET_OS_WATCH
|
||||
Reference in new issue
Block a user