Skip to content

Commit

Permalink
Merge pull request #3827 from Crebs/@W-17749645
Browse files Browse the repository at this point in the history
@W-17749645 Resolve failing unit tests caused by handling of strongSelf
  • Loading branch information
Crebs authored Feb 4, 2025
2 parents 0494f81 + 294c98f commit 6b729d7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ - (void)accessTokenForRefresh:(SFSDKOAuthTokenEndpointRequest *)endpointReq comp
NSURLSession *session = [self createURLSessionWithIdentifier:instanceIdentifier];

__weak typeof(self) weakSelf = self;
NSString *className = NSStringFromClass([self class]);
[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *urlResponse, NSError *error) {
__strong typeof(weakSelf) strongSelf = weakSelf;
SFSDKOAuthTokenEndpointResponse *endpointResponse = nil;
Expand All @@ -293,21 +294,29 @@ - (void)accessTokenForRefresh:(SFSDKOAuthTokenEndpointRequest *)endpointReq comp
endpointResponse = [[SFSDKOAuthTokenEndpointResponse alloc] initWithError:[NSError errorWithDomain:kSFOAuthErrorDomain code:code userInfo:nil]];

if (error.code == NSURLErrorTimedOut) {
[SFSDKCoreLogger d:[strongSelf class] format:@"Refresh attempt timed out after %f seconds.", endpointReq.timeout];
[SFSDKCoreLogger d:[SFSDKOAuth2 class] format:@"Refresh attempt timed out after %f seconds.", endpointReq.timeout];
}

[SFSDKCoreLogger d:[strongSelf class] format:@"SFOAuth2 session failed with error: error code: %ld, description: %@, URL: %@", (long)error.code, [error localizedDescription], errorUrlString];
[SFSDKCoreLogger d:[SFSDKOAuth2 class] format:@"SFOAuth2 session failed with error: error code: %ld, description: %@, URL: %@", (long)error.code, [error localizedDescription], errorUrlString];
dispatch_async(dispatch_get_main_queue(), ^{
if (completionBlock) {
completionBlock(endpointResponse);
}
});
return;
} else {
[SFSDKEventBuilderHelper createAndStoreEvent:@"tokenRefresh" userAccount:[SFUserAccountManager sharedInstance].currentUser className:NSStringFromClass([strongSelf class]) attributes:nil];
}

[strongSelf handleTokenEndpointResponse:completionBlock request:endpointReq data:data urlResponse:urlResponse];
[SFSDKEventBuilderHelper createAndStoreEvent:@"tokenRefresh" userAccount:[SFUserAccountManager sharedInstance].currentUser className:className attributes:nil];
if (strongSelf) {
[strongSelf handleTokenEndpointResponse:completionBlock request:endpointReq data:data urlResponse:urlResponse];
} else {
[SFSDKCoreLogger d:[SFSDKOAuth2 class] format:@"Token endpoint response handler skipped because self was deallocated."];
dispatch_async(dispatch_get_main_queue(), ^{
if (completionBlock) {
completionBlock(nil);
}
});
}
}] resume];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ class RestClientTests: XCTestCase {
}
}

// TODO: Add back after fixing Flappiness
func _testAsyncBatchRequestStopOnFailure() async throws {
func testAsyncBatchRequestStopOnFailure() async throws {
do {
// Create account
let accountName = self.generateRecordName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ - (void)testCredentialsCoding {
credsIn = nil;
}

// TODO: Add back after fixing Flappiness
- (void)_testCredentialsCopying {
- (void)testCredentialsCopying {
NSString *domainToCheck = @"login.salesforce.com";
NSString *redirectUriToCheck = @"redirectUri://done";
NSString *jwtToCheck = @"jwtToken";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ - (void)testCreateBogusContact {
// - delete object (requestForDeleteWithObjectType)
// - query new object (requestForQuery) and make sure we don't get anything
// - search new object (requestForSearch) and make sure we don't get anything
- (void)_testCreateQuerySearchDelete {
- (void)testCreateQuerySearchDelete {
// create object
//use a SOSL-safe format here to avoid problems with escaping characters for SOSL
NSString *lastName = [self generateRecordName];
Expand Down Expand Up @@ -1447,8 +1447,7 @@ - (void) testCollectionUpsertExistingRecords {
XCTAssertEqualObjects(accountsRetrieved[1][@"Name"], secondAccountNameUpdated);
}

// TODO: Add back after fixing Flappiness
- (void) _testCollectionUpdate {
- (void) testCollectionUpdate {
NSString* firstAccountName = [NSString stringWithFormat:@"%@_account_1_%lf", ENTITY_PREFIX_NAME, CFAbsoluteTimeGetCurrent()];
NSString* secondAccountName = [NSString stringWithFormat:@"%@_account_2_%lf", ENTITY_PREFIX_NAME, CFAbsoluteTimeGetCurrent()];
NSString* contactName = [NSString stringWithFormat:@"%@_contact_%lf", ENTITY_PREFIX_NAME, CFAbsoluteTimeGetCurrent()];
Expand Down Expand Up @@ -1937,8 +1936,7 @@ - (void)testUploadBatchDetailsDeleteFilesCommunity {
}

// Upload files / get owned files / delete files / get owned files again
// TODO: Add back after fixing Flappiness
- (void)_testUploadOwnedFilesDelete {
- (void)testUploadOwnedFilesDelete {

// upload first file
NSDictionary *fileAttrs = [self uploadFile];
Expand Down

0 comments on commit 6b729d7

Please sign in to comment.