mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-04-24 03:45:58 +08:00
[ASDataController] Use 2 Threads Per CPU When Measuring Nodes (#2145)
* [ASDataController] Use custom apply function to control thread count * Relax the test for stupid Travis CI * Remove unneeded import
This commit is contained in:
38
AsyncDisplayKitTests/ASDispatchTests.m
Normal file
38
AsyncDisplayKitTests/ASDispatchTests.m
Normal file
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// ASDispatchTests.m
|
||||
// AsyncDisplayKit
|
||||
//
|
||||
// Created by Adlai Holler on 8/25/16.
|
||||
// Copyright © 2016 Facebook. All rights reserved.
|
||||
//
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
#import "ASDispatch.h"
|
||||
|
||||
@interface ASDispatchTests : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation ASDispatchTests
|
||||
|
||||
- (void)testDispatchApply
|
||||
{
|
||||
dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||||
NSInteger expectedThreadCount = [NSProcessInfo processInfo].activeProcessorCount * 2;
|
||||
NSLock *lock = [NSLock new];
|
||||
NSMutableSet *threads = [NSMutableSet set];
|
||||
NSMutableIndexSet *indices = [NSMutableIndexSet indexSet];
|
||||
|
||||
size_t const iterations = 1E5;
|
||||
ASDispatchApply(iterations, q, 0, ^(size_t i) {
|
||||
[lock lock];
|
||||
[threads addObject:[NSThread currentThread]];
|
||||
XCTAssertFalse([indices containsIndex:i]);
|
||||
[indices addIndex:i];
|
||||
[lock unlock];
|
||||
});
|
||||
XCTAssertLessThanOrEqual(threads.count, expectedThreadCount);
|
||||
XCTAssertEqualObjects(indices, [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, iterations)]);
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user