Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start a thrash test suite for the collection node #1246

Merged
merged 12 commits into from
Jan 3, 2019
Prev Previous commit
Next Next commit
One more test
  • Loading branch information
mikezucc committed Dec 18, 2018
commit d29cb0e85a8cbba2fa0f1bb48e72dc9e027109df
50 changes: 40 additions & 10 deletions Tests/ASCollectionViewThrashTests.mm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ASTableViewThrashTests.mm
// ASCollectionViewThrashTests.mm
// Texture
//
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
Expand Down Expand Up @@ -33,12 +33,14 @@ - (void)tearDown {
}

// NOTE: Despite the documentation, this is not always called if an exception is caught.
- (void)recordFailureWithDescription:(NSString *)description inFile:(NSString *)filePath atLine:(NSUInteger)lineNumber expected:(BOOL)expected {
- (void)recordFailureWithDescription:(NSString *)description inFile:(NSString *)filePath atLine:(NSUInteger)lineNumber expected:(BOOL)expected
{
_failed = YES;
[super recordFailureWithDescription:description inFile:filePath atLine:lineNumber expected:expected];
}

- (void)verifyDataSource:(ASThrashDataSource *)ds {
- (void)verifyDataSource:(ASThrashDataSource *)ds
{
CollectionView *collectionView = ds.collectionView;
NSArray <ASThrashTestSection *> *data = [ds data];
for (NSInteger i = 0; i < collectionView.numberOfSections; i++) {
Expand All @@ -55,14 +57,15 @@ - (void)verifyDataSource:(ASThrashDataSource *)ds {

#pragma mark Test Methods

// Disabled temporarily due to issue where cell nodes are not marked invisible before deallocation.
- (void)testInitialDataRead {
- (void)testInitialDataRead
{
ASThrashDataSource *ds = [[ASThrashDataSource alloc] initCollectionViewDataSourceWithData:[ASThrashTestSection sectionsWithCount:kInitialSectionCount]];
[self verifyDataSource:ds];
}

/// Replays the Base64 representation of an ASThrashUpdate from "ASThrashTestRecordedCase" file
- (void)testRecordedThrashCase {
- (void)testRecordedThrashCase
{
NSURL *caseURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"ASThrashTestRecordedCase" withExtension:nil subdirectory:@"TestResources"];
NSString *base64 = [NSString stringWithContentsOfURL:caseURL encoding:NSUTF8StringEncoding error:NULL];

Expand All @@ -72,16 +75,15 @@ - (void)testRecordedThrashCase {
}

ASThrashDataSource *ds = [[ASThrashDataSource alloc] initCollectionViewDataSourceWithData:_update.oldData];
// why is ds.collectionView.test_enableSuperUpdateCallLogging available on table view but now collection view>?
// ds.collectionView.test_enableSuperUpdateCallLogging = YES;
[self applyUpdateUsingBatchUpdates:_update
toDataSource:ds
animated:NO
useXCTestWait:YES];
[self verifyDataSource:ds];
}

- (void)testThrashingWildly {
- (void)testThrashingWildly
{
for (NSInteger i = 0; i < kThrashingIterationCount; i++) {
[self setUp];
@autoreleasepool {
Expand All @@ -102,7 +104,35 @@ - (void)testThrashingWildly {
}
}

- (void)testThrashingWildlyDispatchWildly {
- (void)testThrashingWildlyOnSameCollectionView
{
XCTestExpectation *expectation = [self expectationWithDescription:@"last test ran"];
ASThrashDataSource *ds = [[ASThrashDataSource alloc] initCollectionViewDataSourceWithData:nil];
for (NSInteger i = 0; i < 1000; i++) {
[self setUp];
@autoreleasepool {
NSArray *sections = [ASThrashTestSection sectionsWithCount:kInitialSectionCount];
_update = [[ASThrashUpdate alloc] initWithData:sections];
[ds setData:sections];
[ds.collectionView reloadData];

[self applyUpdateUsingBatchUpdates:_update
toDataSource:ds
animated:NO
useXCTestWait:NO];
[self verifyDataSource:ds];
if (i == 999) {
[expectation fulfill];
}
}

[self tearDown];
}
[self waitForExpectationsWithTimeout:3 handler:nil];
}

- (void)testThrashingWildlyDispatchWildly
{
XCTestExpectation *expectation = [self expectationWithDescription:@"last test ran"];
for (NSInteger i = 0; i < kThrashingIterationCount; i++) {
[self setUp];
Expand Down
4 changes: 2 additions & 2 deletions Tests/ASThrashUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
#define kMinimumItemCount 5
#define kMinimumSectionCount 3
#define kFickleness 0.1
#define kThrashingIterationCount 100
#define kThrashingIterationCount 10

// Set to 1 to use UITableView and see if the issue still exists.
#define USE_UIKIT_REFERENCE 0
Expand Down Expand Up @@ -69,7 +69,7 @@ static atomic_uint ASThrashTestItemNextID;
@property (nonatomic) ASWeakSet *allNodes;

- (instancetype)initTableViewDataSourceWithData:(NSArray <ASThrashTestSection *> *)data;
- (instancetype)initCollectionViewDataSourceWithData:(NSArray <ASThrashTestSection *> *)data;
- (instancetype)initCollectionViewDataSourceWithData:(NSArray <ASThrashTestSection *> * _Nullable)data;
- (NSPredicate *)predicateForDeallocatedHierarchy;
@end

Expand Down
6 changes: 5 additions & 1 deletion Tests/ASThrashUtility.m
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ - (instancetype)initTableViewDataSourceWithData:(NSArray <ASThrashTestSection *>
- (instancetype)initCollectionViewDataSourceWithData:(NSArray <ASThrashTestSection *> *)data {
self = [super init];
if (self != nil) {
_data = [[NSArray alloc] initWithArray:data copyItems:YES];
_data = data != nil ? [[NSArray alloc] initWithArray:data copyItems:YES] : [[NSArray alloc] init];
_window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
_collectionView = [[CollectionView alloc] initWithCollectionViewLayout:[[UICollectionViewFlowLayout alloc] init]];
_allNodes = [[ASWeakSet alloc] init];
Expand All @@ -209,6 +209,10 @@ - (instancetype)initCollectionViewDataSourceWithData:(NSArray <ASThrashTestSecti
return self;
}

- (void)setData:(NSArray<ASThrashTestSection *> *)data {
_data = data;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.data[section].items.count;
}
Expand Down