mirror of
https://github.com/TextureGroup/Texture.git
synced 2026-04-07 19:17:39 +00:00
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.
57 lines
1.9 KiB
Objective-C
57 lines
1.9 KiB
Objective-C
//
|
|
// 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
|