-
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.
Build a test that fires up 2000 threads to instantiate `ASTextKitContext` both with and without the global lock. Both pass down to iOS10 in the simulator. See #1455 for more.
- Loading branch information
Greg Bolsinga
committed
Nov 25, 2019
1 parent
cbc5104
commit a854002
Showing
4 changed files
with
100 additions
and
13 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,56 @@ | ||
// | ||
// ASTextKitContextConcurrencyTests.m | ||
// AsyncDisplayKitTests | ||
// | ||
// Created by Greg Bolsinga on 11/25/19. | ||
// Copyright © 2019 Pinterest. All rights reserved. | ||
// | ||
|
||
#import "ASTestCase.h" | ||
#import <AsyncDisplayKit/ASTextKitContext.h> | ||
|
||
static const NSUInteger ASTextContextConcurrentCount = 2000; | ||
|
||
static void *createContext(void *arg) | ||
{ | ||
BOOL enableGlobalLock = *(BOOL *)arg; | ||
|
||
ASTextKitContext *context = [[ASTextKitContext alloc] initWithAttributedString:[[NSAttributedString alloc] initWithString:@""] | ||
tintColor:nil | ||
lineBreakMode:NSLineBreakByWordWrapping | ||
maximumNumberOfLines:100 | ||
exclusionPaths:nil | ||
constrainedSize:CGSizeZero | ||
enableGlobalLock:enableGlobalLock]; | ||
return (__bridge void *)(context); | ||
} | ||
|
||
@interface ASTextKitContextConcurrencyTests : ASTestCase | ||
|
||
@end | ||
|
||
@implementation ASTextKitContextConcurrencyTests | ||
|
||
- (void)_instantiateTextContextConcurrencyCount:(NSUInteger)concurrencyCount enableGlobalLock:(BOOL)enableGlobalLock | ||
{ | ||
pthread_t threads[concurrencyCount]; | ||
for (NSUInteger i = 0; i < concurrencyCount; i++) { | ||
pthread_create(&threads[i], NULL, createContext, &enableGlobalLock); | ||
} | ||
|
||
for (NSUInteger i = 0; i < concurrencyCount; i++) { | ||
pthread_join(threads[i], NULL); | ||
} | ||
} | ||
|
||
- (void)testTextContextConcurrency_disableGlobalLock | ||
{ | ||
[self _instantiateTextContextConcurrencyCount:ASTextContextConcurrentCount enableGlobalLock:NO]; | ||
} | ||
|
||
- (void)testTextContextConcurrency_default | ||
{ | ||
[self _instantiateTextContextConcurrencyCount:ASTextContextConcurrentCount enableGlobalLock:YES]; | ||
} | ||
|
||
@end |