Skip to content

Commit fcd6779

Browse files
[iOS] Stabilize flaky REST API and auth tests
1 parent fd2a345 commit fcd6779

3 files changed

Lines changed: 333 additions & 87 deletions

File tree

libs/SalesforceSDKCore/SalesforceSDKCore/Classes/Test/TestSetupUtils.m

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,23 @@ + (SFSDKTestCredentialsData *)populateAuthCredentialsFromString:(NSString *)test
7070
}
7171

7272
+ (void)synchronousAuthRefresh {
73-
[self synchronousAuthRefreshWithUserDidLoginNotification:NO];
73+
[self synchronousAuthRefreshWithRetries:3];
74+
}
75+
76+
+ (void)synchronousAuthRefreshWithRetries:(NSInteger)maxRetries {
77+
for (NSInteger attempt = 1; attempt <= maxRetries; attempt++) {
78+
@try {
79+
[self synchronousAuthRefreshWithUserDidLoginNotification:NO];
80+
return;
81+
} @catch (NSException *exception) {
82+
if (attempt < maxRetries) {
83+
NSLog(@"[TestSetupUtils] Auth refresh attempt %ld failed: %@. Retrying in 3s...", (long)attempt, exception.reason);
84+
[NSThread sleepForTimeInterval:3.0];
85+
} else {
86+
@throw;
87+
}
88+
}
89+
}
7490
}
7591

7692
+ (void)synchronousAuthRefreshWithUserDidLoginNotification:(BOOL)postUserDidLogIn

libs/SalesforceSDKCore/SalesforceSDKCoreTests/SFSDKAuthUtilTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class SFSDKAuthUtilTests: XCTestCase {
6161
endpointResponse = response
6262
expectation.fulfill()
6363
}
64-
self.wait(for: [expectation], timeout: 30)
64+
self.wait(for: [expectation], timeout: 60)
6565
let response = try XCTUnwrap(endpointResponse)
6666
XCTAssertFalse(response.hasError)
6767
XCTAssertNotNil(response.accessToken)

0 commit comments

Comments
 (0)