Skip to content

Commit c98a544

Browse files
authored
EMT-2370 setThirdPartyAPIsTimeout Implementation (#1517)
* Added API - setThirdPartyAPIsTimeout, ODM and Apple attribution token will be fetched in parallel now for installs and opens. * OMD Info and Apple Attribution Token will be fetched in parallel. * Added Unit tests. * Refactored BNCODMInfoCollector class. * Refactored appleAttributionToken function. * Disabling ODM Integration Tests - Never Worked.(Network calls related to ODM to Google were failling even though bundle id is in the allow list.
1 parent d7f6b62 commit c98a544

File tree

30 files changed

+362
-406
lines changed

30 files changed

+362
-406
lines changed

Branch-TestBed/Branch-SDK-Tests/BNCAPIServerTest.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ - (void)testSetSafeTrackServiceURLWithUserTrackingDomain {
450450
XCTAssertEqualObjects(storedUrl, expectedUrl);
451451

452452
storedUrl = [[BNCServerAPI sharedInstance] validationServiceURL];
453-
expectedUrl = @"https://links.toTestDomain.com/v1/app-link-settings";
453+
expectedUrl = @"https://api3.branch.io/v1/app-link-settings";
454454
XCTAssertEqualObjects(storedUrl, expectedUrl);
455455

456456
[BNCServerAPI sharedInstance].useTrackingDomain = NO;
@@ -501,7 +501,7 @@ - (void)testSetSafeTrackServiceURLWithOutUserTrackingDomain {
501501
XCTAssertEqualObjects(storedUrl, expectedUrl);
502502

503503
storedUrl = [[BNCServerAPI sharedInstance] validationServiceURL];
504-
expectedUrl = @"https://links.toTestDomain.com/v1/app-link-settings";
504+
expectedUrl = @"https://api3.branch.io/v1/app-link-settings";
505505
XCTAssertEqualObjects(storedUrl, expectedUrl);
506506

507507
[BNCServerAPI sharedInstance].useTrackingDomain = NO;

Branch-TestBed/Branch-SDK-Tests/BNCODMTests.m

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ - (void)testSetODMandSDKRequests {
6565
}
6666

6767
- (void)testODMTimeOut {
68-
68+
6969
NSString* requestUUID = [[NSUUID UUID ] UUIDString];
7070
NSNumber* requestCreationTimeStamp = BNCWireFormatFromDate([NSDate date]);
7171
NSString *odm = @"testODMString";
@@ -80,21 +80,23 @@ - (void)testODMTimeOut {
8080

8181
sleep(10);
8282

83-
NSDictionary *jsonOpen = [factory dataForOpenWithURLString:@"https://branch.io"];
83+
BNCRequestFactory *factory2 = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:requestUUID TimeStamp:requestCreationTimeStamp];
84+
NSDictionary *jsonOpen = [factory2 dataForOpenWithURLString:@"https://branch.io"];
8485
XCTAssertTrue(![odm isEqualToString:[jsonOpen objectForKey:@"odm_info"]]);
8586

8687
self.prefHelper.odmInfo = nil;
8788
self.prefHelper.odmInfoInitDate = nil;
88-
89+
8990
}
9091

9192

9293
- (void) testODMAPIsNotLoaded {
94+
9395
XCTestExpectation *expectation = [self expectationWithDescription:@"Check if ODCManager class is loaded."];
94-
[[BNCODMInfoCollector instance ] loadODMInfoWithTimeOut:DISPATCH_TIME_FOREVER andCompletionHandler:^(NSString * _Nullable odmInfo, NSError * _Nullable error) {
95-
if (error.code == BNCClassNotFoundError){
96-
[expectation fulfill];
97-
}
96+
[[BNCODMInfoCollector instance ] loadODMInfoWithCompletionHandler:^(NSString * _Nullable odmInfo, NSError * _Nullable error) {
97+
if (error.code == BNCClassNotFoundError){
98+
[expectation fulfill];
99+
}
98100
}];
99101
[self waitForExpectationsWithTimeout:15 handler:nil];
100102
}

Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,4 +414,27 @@ - (void)testSaveContentAnalyticsManifest {
414414
XCTAssertEqualObjects(retrievedManifest, dummyManifest);
415415
}
416416

417+
- (void)testThirdPartyAPIsTimeoutDefaultValue {
418+
XCTAssertEqual(self.prefHelper.thirdPartyAPIsWaitTime, 0.5,
419+
@"Default third party APIs timeout should be 0.5 seconds");
420+
}
421+
422+
- (void)testThirdPartyAPIsTimeoutSetterGetter {
423+
NSTimeInterval testTimeout1 = 1.0;
424+
self.prefHelper.thirdPartyAPIsWaitTime = testTimeout1;
425+
XCTAssertEqual(self.prefHelper.thirdPartyAPIsWaitTime, testTimeout1,
426+
@"Third party APIs timeout should be settable and retrievable");
427+
428+
NSTimeInterval testTimeout2 = 2.5;
429+
self.prefHelper.thirdPartyAPIsWaitTime = testTimeout2;
430+
XCTAssertEqual(self.prefHelper.thirdPartyAPIsWaitTime, testTimeout2,
431+
@"Third party APIs timeout should be updatable");
432+
433+
NSTimeInterval testTimeout3 = 0.1;
434+
self.prefHelper.thirdPartyAPIsWaitTime = testTimeout3;
435+
XCTAssertEqual(self.prefHelper.thirdPartyAPIsWaitTime, testTimeout3,
436+
@"Third party APIs timeout should support small values");
437+
}
438+
439+
417440
@end

Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ - (void)writeObjectToDefaults:(NSString *)key value:(NSObject *)value;
2020

2121
@interface BranchClassTests : XCTestCase
2222
@property (nonatomic, strong) Branch *branch;
23+
@property (nonatomic, strong, readwrite) BNCPreferenceHelper *prefHelper;
2324
@end
2425

2526
@implementation BranchClassTests
2627

2728
- (void)setUp {
2829
[super setUp];
2930
self.branch = [Branch getInstance];
31+
self.prefHelper = [BNCPreferenceHelper sharedInstance];
3032
}
3133

3234
- (void)tearDown {
@@ -261,6 +263,102 @@ - (void)testSetConsumerProtectionAttributionLevel {
261263

262264
}
263265

266+
- (void)testBranchSetSDKWaitTimeForThirdPartyAPIs {
267+
// Test Branch instance method for setting timeout
268+
NSTimeInterval testTimeout = 2.0;
269+
[Branch setSDKWaitTimeForThirdPartyAPIs:testTimeout];
270+
271+
// Verify it was set in the preference helper
272+
XCTAssertEqual(self.prefHelper.thirdPartyAPIsWaitTime, testTimeout,
273+
@"Branch setSDKWaitTimeForThirdPartyAPIs should update preference helper");
274+
}
275+
276+
- (void)testBranchSetSDKWaitTimeForThirdPartyAPIsMultipleValues {
277+
// Test setting multiple different values
278+
NSArray *testValues = @[@0.5, @1.0, @1.5, @3.0, @5.0];
279+
280+
for (NSNumber *timeoutValue in testValues) {
281+
NSTimeInterval timeout = [timeoutValue doubleValue];
282+
[Branch setSDKWaitTimeForThirdPartyAPIs:timeout];
283+
284+
XCTAssertEqual(self.prefHelper.thirdPartyAPIsWaitTime, timeout,
285+
@"Branch setSDKWaitTimeForThirdPartyAPIs should handle value %.1f", timeout);
286+
}
287+
}
288+
289+
- (void)testTimeoutIntegrationWithPreferenceHelper {
290+
// Test that Branch and PreferenceHelper work together correctly
291+
NSTimeInterval branchTimeout = 1.8;
292+
NSTimeInterval directTimeout = 2.3;
293+
294+
// Set via Branch
295+
[Branch setSDKWaitTimeForThirdPartyAPIs:branchTimeout];
296+
XCTAssertEqual(self.prefHelper.thirdPartyAPIsWaitTime, branchTimeout,
297+
@"Wait Time set via Branch should be readable from PreferenceHelper");
298+
299+
// Set directly on PreferenceHelper
300+
self.prefHelper.thirdPartyAPIsWaitTime = directTimeout;
301+
XCTAssertEqual(self.prefHelper.thirdPartyAPIsWaitTime, directTimeout,
302+
@"Wait time set directly should be readable via Branch");
303+
}
304+
305+
- (void)testTimeoutValueConsistency {
306+
// Test that the same instance maintains consistent values
307+
NSTimeInterval testTimeout = 1.25;
308+
309+
[Branch setSDKWaitTimeForThirdPartyAPIs:testTimeout];
310+
311+
// Read multiple times to ensure consistency
312+
for (int i = 0; i < 5; i++) {
313+
XCTAssertEqual(self.prefHelper.thirdPartyAPIsWaitTime, testTimeout,
314+
@"Timeout value should remain consistent across multiple reads");
315+
}
316+
}
317+
318+
- (void)testBranchSetSDKWaitTimeForThirdPartyAPIsInvalidLowValues {
319+
320+
NSArray *invalidLowValues = @[@0.0, @-1.0, @-0.5];
321+
NSTimeInterval originalTimeout = [BNCPreferenceHelper sharedInstance].thirdPartyAPIsWaitTime;
322+
323+
for (NSNumber *timeoutValue in invalidLowValues) {
324+
NSTimeInterval timeout = [timeoutValue doubleValue];
325+
[Branch setSDKWaitTimeForThirdPartyAPIs:timeout];
326+
XCTAssertEqual([BNCPreferenceHelper sharedInstance].thirdPartyAPIsWaitTime, originalTimeout,
327+
@"Branch setSDKWaitTimeForThirdPartyAPIs should reject invalid low value %.3f", timeout);
328+
}
329+
}
330+
331+
- (void)testBranchsetSDKWaitTimeForThirdPartyAPIsInvalidHighValues {
332+
333+
NSArray *invalidHighValues = @[@10.1, @15.0, @30.0, @60.0];
334+
NSTimeInterval originalTimeout = [BNCPreferenceHelper sharedInstance].thirdPartyAPIsWaitTime;
335+
336+
for (NSNumber *timeoutValue in invalidHighValues) {
337+
NSTimeInterval timeout = [timeoutValue doubleValue];
338+
[Branch setSDKWaitTimeForThirdPartyAPIs:timeout];
339+
XCTAssertEqual([BNCPreferenceHelper sharedInstance].thirdPartyAPIsWaitTime, originalTimeout,
340+
@"Branch setSDKWaitTimeForThirdPartyAPIs should reject invalid high value %.3f", timeout);
341+
}
342+
}
343+
344+
- (void)testBranchSetSDKWaitTimeForThirdPartyAPIsBoundaryValues {
345+
346+
// Test exactly 10.0 (should be valid)
347+
[Branch setSDKWaitTimeForThirdPartyAPIs:10.0];
348+
XCTAssertEqual([BNCPreferenceHelper sharedInstance].thirdPartyAPIsWaitTime, 10.0,
349+
@"Timeout of exactly 10.0 seconds should be valid");
350+
351+
// Test just over 10.0 (should be invalid)
352+
[Branch setSDKWaitTimeForThirdPartyAPIs:10.0001];
353+
XCTAssertEqual([BNCPreferenceHelper sharedInstance].thirdPartyAPIsWaitTime, 10.0,
354+
@"Timeout of 10.0001 seconds should be rejected");
355+
356+
// Test very small positive value (should be valid)
357+
[Branch setSDKWaitTimeForThirdPartyAPIs:0.0001];
358+
XCTAssertEqual([BNCPreferenceHelper sharedInstance].thirdPartyAPIsWaitTime, 0.0001,
359+
@"Very small positive timeout should be valid");
360+
}
361+
264362
- (void)testSetAnonID {
265363
NSString *expectedAnonID = @"static-test-anon-id-12345";
266364

@@ -358,5 +456,4 @@ - (void)testSetAnonID_ThreadSafety {
358456
@"One of the anonID values should be set");
359457
}
360458

361-
362459
@end

Branch-TestBed/Branch-TestBed-CI.xctestplan

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
},
1414
"testTargets" : [
1515
{
16+
"enabled" : false,
1617
"target" : {
1718
"containerPath" : "container:Branch-TestBed.xcodeproj",
1819
"identifier" : "E7AC745F2DB064BC002D8C40",

Branch-TestBed/Branch-TestBed.xcodeproj/Branch-TestBed.xctestplan

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
}
3838
},
3939
{
40+
"skippedTests" : [
41+
"Reflection_ODM_Tests",
42+
"Reflection_ODM_Tests\/testODMAPICall",
43+
"Reflection_ODM_Tests\/testODMAPIsLoaded"
44+
],
4045
"target" : {
4146
"containerPath" : "container:Branch-TestBed.xcodeproj",
4247
"identifier" : "E7AC745F2DB064BC002D8C40",

0 commit comments

Comments
 (0)