diff options
author | Julian Rex <julian.rex@mapbox.com> | 2019-07-15 21:11:17 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-15 21:11:17 -0400 |
commit | 3c488e05efdb9415e658fa820504692b906c3443 (patch) | |
tree | 25f883c677594f212b9c9c5ac6291e8e99f77054 /platform/ios/test/MGLNetworkConfigurationTests.m | |
parent | cdd47c035807583c0437bd75a0deb3347037042d (diff) | |
download | qtlocation-mapboxgl-3c488e05efdb9415e658fa820504692b906c3443.tar.gz |
[ios] Adds thread safe access to MGLNetworkConfiguration events dictionary (#15113)
Diffstat (limited to 'platform/ios/test/MGLNetworkConfigurationTests.m')
-rw-r--r-- | platform/ios/test/MGLNetworkConfigurationTests.m | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/platform/ios/test/MGLNetworkConfigurationTests.m b/platform/ios/test/MGLNetworkConfigurationTests.m new file mode 100644 index 0000000000..bfb63f57af --- /dev/null +++ b/platform/ios/test/MGLNetworkConfigurationTests.m @@ -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 |