This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ios] Cherry picks #15113 - Adds thread safe access to MGLNetworkConf…
…iguration events dictionary (#15202)
- Loading branch information
Julian Rex
authored
Jul 24, 2019
1 parent
75e0b7c
commit 3323574
Showing
4 changed files
with
89 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#import <Mapbox/Mapbox.h> | ||
#import <XCTest/XCTest.h> | ||
#import "MGLNetworkConfiguration_Private.h" | ||
|
||
@interface MGLNetworkConfigurationTests : XCTestCase | ||
@end | ||
|
||
@implementation MGLNetworkConfigurationTests | ||
|
||
// Regression test for https://github.com/mapbox/mapbox-gl-native/issues/14982 | ||
- (void)testAccessingEventsFromMultipleThreads { | ||
MGLNetworkConfiguration *configuration = [[MGLNetworkConfiguration alloc] init]; | ||
|
||
// Concurrent | ||
dispatch_queue_t queue = dispatch_queue_create("com.mapbox.testAccessingEventsFromMultipleThreads", DISPATCH_QUEUE_CONCURRENT); | ||
|
||
NSUInteger numberOfConcurrentBlocks = 20; | ||
|
||
XCTestExpectation *expectation = [self expectationWithDescription:@"wait-for-threads"]; | ||
expectation.expectedFulfillmentCount = numberOfConcurrentBlocks; | ||
|
||
for (NSUInteger i = 0; i < numberOfConcurrentBlocks; i++) { | ||
|
||
NSString *event = [NSString stringWithFormat:@"test://event-%ld", i]; | ||
NSString *resourceType = @"test"; | ||
|
||
dispatch_async(queue, ^{ | ||
[configuration startDownloadEvent:event type:resourceType]; | ||
|
||
NSURL *url = [NSURL URLWithString:event]; | ||
NSURLResponse *response = [[NSURLResponse alloc] initWithURL:url MIMEType:nil expectedContentLength:0 textEncodingName:nil]; | ||
|
||
[configuration stopDownloadEventForResponse:response]; | ||
|
||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
[expectation fulfill]; | ||
}); | ||
}); | ||
} | ||
|
||
[self waitForExpectations:@[expectation] timeout:10.0]; | ||
} | ||
@end |