Skip to content

Commit 93a8058

Browse files
committed
Update ASTableView test to be more random and more rigorous.
1 parent 1f8aad6 commit 93a8058

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

AsyncDisplayKitTests/ASTableViewTests.m

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#define NumberOfSections 10
1414
#define NumberOfRowsPerSection 20
15-
#define NumberOfReloadIterations 50
15+
#define NumberOfReloadIterations 250
1616

1717
@interface ASTestTableView : ASTableView
1818
@property (atomic, copy) void (^willDeallocBlock)(ASTableView *tableView);
@@ -155,28 +155,34 @@ - (void)testReloadData
155155
[tableView reloadData];
156156

157157
for (int i = 0; i < NumberOfReloadIterations; ++i) {
158-
UITableViewRowAnimation rowAnimation = (arc4random_uniform(1) == 0 ? UITableViewRowAnimationMiddle : UITableViewRowAnimationNone);
159-
160-
BOOL animatedScroll = (arc4random_uniform(1) == 0 ? YES : NO);
161-
BOOL reloadRowsInsteadOfSections = (arc4random_uniform(1) == 0 ? YES : NO);
162-
BOOL letRunloopProceed = (arc4random_uniform(1) == 0 ? YES : NO);
163-
BOOL useBeginEndUpdates = (arc4random_uniform(2) == 0 ? YES : NO);
158+
UITableViewRowAnimation rowAnimation = (arc4random_uniform(2) == 0 ? UITableViewRowAnimationMiddle : UITableViewRowAnimationNone);
159+
BOOL animatedScroll = (arc4random_uniform(2) == 0 ? YES : NO);
160+
BOOL reloadRowsInsteadOfSections = (arc4random_uniform(2) == 0 ? YES : NO);
161+
NSTimeInterval runLoopDelay = ((arc4random_uniform(2) == 0) ? (1.0 / (1 + arc4random_uniform(500))) : 0);
162+
BOOL useBeginEndUpdates = (arc4random_uniform(3) == 0 ? YES : NO);
163+
164+
// instrument our instrumentation ;)
165+
NSLog(@"Iteration %03d: %@|%@|%@|%@|%g", i, (rowAnimation == UITableViewRowAnimationNone) ? @"NONE " : @"MIDDLE", animatedScroll ? @"ASCR" : @" ", reloadRowsInsteadOfSections ? @"ROWS" : @"SECS", useBeginEndUpdates ? @"BEGEND" : @" ", runLoopDelay);
164166

165167
if (useBeginEndUpdates) {
166168
[tableView beginUpdates];
167169
}
168170

169171
if (reloadRowsInsteadOfSections) {
170-
[tableView reloadRowsAtIndexPaths:[self randomIndexPathsExisting:YES] withRowAnimation:rowAnimation];
172+
NSArray *indexPaths = [self randomIndexPathsExisting:YES];
173+
//NSLog(@"reloading rows: %@", indexPaths);
174+
[tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:rowAnimation];
171175
} else {
172-
[tableView reloadSections:[self randomIndexSet] withRowAnimation:rowAnimation];
176+
NSIndexSet *sections = [self randomIndexSet];
177+
//NSLog(@"reloading sections: %@", sections);
178+
[tableView reloadSections:sections withRowAnimation:rowAnimation];
173179
}
174180

175181
[tableView setContentOffset:CGPointMake(0, arc4random_uniform(tableView.contentSize.height - tableView.bounds.size.height)) animated:animatedScroll];
176182

177-
if (letRunloopProceed) {
183+
if (runLoopDelay > 0) {
178184
// Run other stuff on the main queue for between 2ms and 1000ms.
179-
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:(1 / (1 + arc4random_uniform(500)))]];
185+
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:runLoopDelay]];
180186
}
181187

182188
if (useBeginEndUpdates) {

0 commit comments

Comments
 (0)