Skip to content

Commit 9e58c7b

Browse files
Kroach/oasis 1509 concurrent (#187)
* Remove #if ... #endif surrounding testConcurrentMapping * OASIS-1509 Diagnose and fix OPTLYJSONModel's testConcurrentMapping unit test. Summary: Diagnose and fix OPTLYJSONModel's testConcurrentMapping unit test. Remove #if ... #endif surrounding testConcurrentMapping Add lockObject to testConcurrentMapping to synchronize access to local count . Test Plan: * testConcurrentMapping PASSED 120x in a row. * Run bunch of regular test suites even though we don't need to. None of the SDK framework code has changed. The tests should just pass. * 8 iOS test suites PASSED * OptimizelySDKiOS Product > Analyze PASSED * OptimizelyiOSDemoApp PASSED Reviewers: alda JIRA Issues: OASIS-1509 Differential Revision: https://phabricator.optimizely.com/D17953
1 parent 93ee0cb commit 9e58c7b

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

OptimizelySDKCore/OPTLYJSONModelTests/ConcurrentTests.m

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,39 +46,31 @@ - (void)setUp
4646
self.jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&err];
4747
}
4848

49-
#if true
50-
// TODO: This test removed from line up by Optimizely OASIS Team until unreliability
51-
// issues are resolved.
5249
- (void)testConcurrentMapping
5350
{
5451
// Because the uncertainty of concurrency. Need multiple run to confirm the result.
52+
__block NSObject *lockObject = [[NSObject alloc] init];
5553
NSOperationQueue *queue = [NSOperationQueue new];
5654
queue.maxConcurrentOperationCount = 50;
5755
queue.suspended = YES;
58-
5956
XCTestExpectation *expectation = [self expectationWithDescription:@"Wait for queue...."];
60-
6157
__block int count = 0;
62-
6358
for (int i = 0; i < 100; i++)
6459
{
6560
[queue addOperationWithBlock:^
6661
{
6762
ConcurrentReposModel *model = [[ConcurrentReposModel alloc] initWithDictionary:self.jsonDict error:nil];
6863
#pragma unused(model)
69-
70-
count++;
71-
72-
if (count == 100)
73-
[expectation fulfill];
74-
}];
64+
@synchronized (lockObject) {
65+
count++;
66+
if (count == 100) {
67+
[expectation fulfill];
68+
}
69+
}
70+
}];
7571
}
76-
7772
queue.suspended = NO;
78-
7973
[self waitForExpectationsWithTimeout:30 handler:nil];
8074
}
81-
#endif
82-
8375

8476
@end

0 commit comments

Comments
 (0)