Skip to content

Commit 9f47c2e

Browse files
author
kai
committed
enable more tests from [logger retrieveAndFlushExecutionFlowWithCorrelationId:
1 parent a10c1b8 commit 9f47c2e

File tree

1 file changed

+99
-98
lines changed

1 file changed

+99
-98
lines changed

IdentityCore/tests/MSIDExecutionFlowLoggerTests.m

Lines changed: 99 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -634,9 +634,6 @@ - (void)testInsertAfterFlush_shouldBeRejected
634634
[self waitForExpectationsWithTimeout:1 handler:nil];
635635
}
636636

637-
//----------New Batch----------------
638-
639-
640637
#pragma mark - Eliminated Pool Tests
641638

642639
- (void)testEliminatedPool_shouldPreventReaddingSameFlow
@@ -780,101 +777,105 @@ - (void)testConcurrentInsertsWithSameCorrelationId_shouldHandleThreadSafely
780777

781778
[self waitForExpectationsWithTimeout:1 handler:nil];
782779
}
783-
//
784-
//- (void)testConcurrentInsertsWithDifferentCorrelationIds_shouldNotInterfere
785-
//{
786-
// MSIDExecutionFlowLogger *logger = [MSIDExecutionFlowLogger sharedInstance];
787-
//
788-
// dispatch_group_t group = dispatch_group_create();
789-
// dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
790-
//
791-
// NSMutableArray *correlationIds = [NSMutableArray new];
792-
// for (int i = 0; i < 10; i++) {
793-
// NSUUID *correlationId = [NSUUID UUID];
794-
// [correlationIds addObject:correlationId];
795-
// [logger registerExecutionFlowWithCorrelationId:correlationId];
796-
// }
797-
//
798-
// // Insert from multiple threads with different correlationIds
799-
// for (int i = 0; i < 10; i++) {
800-
// dispatch_group_async(group, queue, ^{
801-
// [logger insertTag:[NSString stringWithFormat:@"Tag%d", i]
802-
// extraInfo:nil
803-
// withCorrelationId:correlationIds[i]];
804-
// });
805-
// }
806-
//
807-
// dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
808-
//
809-
// // Verify all flows were created
810-
// XCTestExpectation *allFlowsExpectation = [self expectationWithDescription:@"all separate flows retrieved"];
811-
// allFlowsExpectation.expectedFulfillmentCount = 10;
812-
//
813-
// for (int i = 0; i < 10; i++) {
814-
// [logger retrieveAndFlushExecutionFlowWithCorrelationId:correlationIds[i] queryKeys:nil completion:^(NSString * _Nullable executionFlow) {
815-
// XCTAssertNotNil(executionFlow, @"Flow should exist for correlationId %d", i);
816-
// [allFlowsExpectation fulfill];
817-
// }];
818-
// }
819-
//
820-
// [self waitForExpectationsWithTimeout:1 handler:nil];
821-
//}
822-
//
823-
//- (void)testConcurrentInsertAndRetrieve_shouldNotCrash
824-
//{
825-
// MSIDExecutionFlowLogger *logger = [MSIDExecutionFlowLogger sharedInstance];
826-
// NSUUID *correlationId = [NSUUID UUID];
827-
//
828-
// [logger registerExecutionFlowWithCorrelationId:correlationId];
829-
//
830-
// dispatch_group_t group = dispatch_group_create();
831-
// dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
832-
//
833-
// // Concurrent inserts
834-
// for (int i = 0; i < 10; i++) {
835-
// dispatch_group_async(group, queue, ^{
836-
// [logger insertTag:[NSString stringWithFormat:@"Tag%d", i]
837-
// extraInfo:nil
838-
// withCorrelationId:correlationId];
839-
// });
840-
// }
841-
//
842-
// // Concurrent retrieve (may or may not get data depending on timing)
843-
// dispatch_group_enter(group);
844-
// dispatch_async(queue, ^{
845-
// [logger retrieveAndFlushExecutionFlowWithCorrelationId:correlationId queryKeys:nil completion:^(NSString * _Nullable executionFlow) {
846-
// dispatch_group_leave(group);
847-
// }];
848-
// });
849-
//
850-
// dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
851-
//
852-
// // Test passes if no crash occurs
853-
//}
854-
//
855-
//- (void)testConcurrentRegistrations_shouldHandleThreadSafely
856-
//{
857-
// MSIDExecutionFlowLogger *logger = [MSIDExecutionFlowLogger sharedInstance];
858-
//
859-
// dispatch_group_t group = dispatch_group_create();
860-
// dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
861-
//
862-
// NSMutableArray *correlationIds = [NSMutableArray new];
863-
// for (int i = 0; i < 20; i++) {
864-
// [correlationIds addObject:[NSUUID UUID]];
865-
// }
866-
//
867-
// // Register from multiple threads
868-
// for (int i = 0; i < 20; i++) {
869-
// dispatch_group_async(group, queue, ^{
870-
// [logger registerExecutionFlowWithCorrelationId:correlationIds[i]];
871-
// });
872-
// }
873-
//
874-
// dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
875-
//
876-
// // Test passes if no crash occurs
877-
//}
780+
781+
//----------New Batch----------------
782+
783+
784+
785+
- (void)testConcurrentInsertsWithDifferentCorrelationIds_shouldNotInterfere
786+
{
787+
MSIDExecutionFlowLogger *logger = [MSIDExecutionFlowLogger sharedInstance];
788+
789+
dispatch_group_t group = dispatch_group_create();
790+
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
791+
792+
NSMutableArray *correlationIds = [NSMutableArray new];
793+
for (int i = 0; i < 10; i++) {
794+
NSUUID *correlationId = [NSUUID UUID];
795+
[correlationIds addObject:correlationId];
796+
[logger registerExecutionFlowWithCorrelationId:correlationId];
797+
}
798+
799+
// Insert from multiple threads with different correlationIds
800+
for (int i = 0; i < 10; i++) {
801+
dispatch_group_async(group, queue, ^{
802+
[logger insertTag:[NSString stringWithFormat:@"Tag%d", i]
803+
extraInfo:nil
804+
withCorrelationId:correlationIds[i]];
805+
});
806+
}
807+
808+
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
809+
810+
// Verify all flows were created
811+
XCTestExpectation *allFlowsExpectation = [self expectationWithDescription:@"all separate flows retrieved"];
812+
allFlowsExpectation.expectedFulfillmentCount = 10;
813+
814+
for (int i = 0; i < 10; i++) {
815+
[logger retrieveAndFlushExecutionFlowWithCorrelationId:correlationIds[i] queryKeys:nil completion:^(NSString * _Nullable executionFlow) {
816+
XCTAssertNotNil(executionFlow, @"Flow should exist for correlationId %d", i);
817+
[allFlowsExpectation fulfill];
818+
}];
819+
}
820+
821+
[self waitForExpectationsWithTimeout:1 handler:nil];
822+
}
823+
824+
- (void)testConcurrentInsertAndRetrieve_shouldNotCrash
825+
{
826+
MSIDExecutionFlowLogger *logger = [MSIDExecutionFlowLogger sharedInstance];
827+
NSUUID *correlationId = [NSUUID UUID];
828+
829+
[logger registerExecutionFlowWithCorrelationId:correlationId];
830+
831+
dispatch_group_t group = dispatch_group_create();
832+
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
833+
834+
// Concurrent inserts
835+
for (int i = 0; i < 10; i++) {
836+
dispatch_group_async(group, queue, ^{
837+
[logger insertTag:[NSString stringWithFormat:@"Tag%d", i]
838+
extraInfo:nil
839+
withCorrelationId:correlationId];
840+
});
841+
}
842+
843+
// Concurrent retrieve (may or may not get data depending on timing)
844+
dispatch_group_enter(group);
845+
dispatch_async(queue, ^{
846+
[logger retrieveAndFlushExecutionFlowWithCorrelationId:correlationId queryKeys:nil completion:^(NSString * _Nullable executionFlow) {
847+
dispatch_group_leave(group);
848+
}];
849+
});
850+
851+
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
852+
853+
// Test passes if no crash occurs
854+
}
855+
856+
- (void)testConcurrentRegistrations_shouldHandleThreadSafely
857+
{
858+
MSIDExecutionFlowLogger *logger = [MSIDExecutionFlowLogger sharedInstance];
859+
860+
dispatch_group_t group = dispatch_group_create();
861+
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
862+
863+
NSMutableArray *correlationIds = [NSMutableArray new];
864+
for (int i = 0; i < 20; i++) {
865+
[correlationIds addObject:[NSUUID UUID]];
866+
}
867+
868+
// Register from multiple threads
869+
for (int i = 0; i < 20; i++) {
870+
dispatch_group_async(group, queue, ^{
871+
[logger registerExecutionFlowWithCorrelationId:correlationIds[i]];
872+
});
873+
}
874+
875+
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
876+
877+
// Test passes if no crash occurs
878+
}
878879
//
879880
//#pragma mark - Integration Tests
880881
//

0 commit comments

Comments
 (0)