mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-23 09:18:29 +00:00
Avoid rare crash when update queued during batch
Summary: A new crash! I think this has been a pretty low-firing outlier for some time. Pretty excited to find this. Exposed when adding bg updating as things were likely to collide more frequently, instead of being blocked by main. Unit test fails w/out the patch applied to the updater. Depends on D5392269 Reviewed By: jeremycohen Differential Revision: D5392301 fbshipit-source-id: 5b24d1b41e2a0bdba2b6bc2bfa4f6eeeb36fc4f1
This commit is contained in:
parent
57bd9e24fe
commit
3dc6060a38
3 changed files with 49 additions and 0 deletions
|
|
@ -5,6 +5,10 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag
|
|||
3.1.0 (**upcoming release**)
|
||||
-----
|
||||
|
||||
### Fixes
|
||||
|
||||
- Prevent a crash when update queued immediately after item batch update. [Ryan Nystrom](https://github.com/rnystrom) (tbd)
|
||||
|
||||
3.0.0
|
||||
-----
|
||||
|
||||
|
|
|
|||
|
|
@ -94,6 +94,10 @@
|
|||
}
|
||||
|
||||
static NSArray *objectsWithDuplicateIdentifiersRemoved(NSArray<id<IGListDiffable>> *objects) {
|
||||
if (objects == nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSMutableSet *identifiers = [NSMutableSet new];
|
||||
NSMutableArray *uniqueObjects = [NSMutableArray new];
|
||||
for (id<IGListDiffable> object in objects) {
|
||||
|
|
|
|||
|
|
@ -1480,4 +1480,45 @@
|
|||
[self waitForExpectationsWithTimeout:30 handler:nil];
|
||||
}
|
||||
|
||||
- (void)test_whenUpdateQueuedDuringBatch_thatUpdateCompletesWithoutCrashing {
|
||||
[self setupWithObjects:@[
|
||||
genTestObject(@1, @4),
|
||||
genTestObject(@2, @4),
|
||||
genTestObject(@3, @4),
|
||||
genTestObject(@4, @4),
|
||||
]];
|
||||
|
||||
IGTestObject *object = self.dataSource.objects[0];
|
||||
IGTestDelegateController *sectionController = [self.adapter sectionControllerForObject:object];
|
||||
|
||||
XCTestExpectation *expect1 = genExpectation;
|
||||
XCTestExpectation *expect2 = genExpectation;
|
||||
|
||||
[sectionController.collectionContext performBatchAnimated:YES updates:^(id<IGListBatchContext> batchContext) {
|
||||
object.value = @3;
|
||||
[batchContext deleteInSectionController:sectionController atIndexes:[NSIndexSet indexSetWithIndex:0]];
|
||||
|
||||
self.dataSource.objects = @[
|
||||
genTestObject(@2, @4),
|
||||
genTestObject(@4, @4),
|
||||
genTestObject(@1, @3),
|
||||
];
|
||||
[self.adapter performUpdatesAnimated:YES completion:^(BOOL finished) {
|
||||
XCTAssertEqual([self.collectionView numberOfSections], 3);
|
||||
XCTAssertEqual([self.collectionView numberOfItemsInSection:0], 4);
|
||||
XCTAssertEqual([self.collectionView numberOfItemsInSection:1], 4);
|
||||
XCTAssertEqual([self.collectionView numberOfItemsInSection:2], 3);
|
||||
[expect1 fulfill];
|
||||
}];
|
||||
} completion:^(BOOL finished2) {
|
||||
XCTAssertEqual([self.collectionView numberOfSections], 4);
|
||||
XCTAssertEqual([self.collectionView numberOfItemsInSection:0], 3);
|
||||
XCTAssertEqual([self.collectionView numberOfItemsInSection:1], 4);
|
||||
XCTAssertEqual([self.collectionView numberOfItemsInSection:2], 4);
|
||||
XCTAssertEqual([self.collectionView numberOfItemsInSection:3], 4);
|
||||
[expect2 fulfill];
|
||||
}];
|
||||
[self waitForExpectationsWithTimeout:30 handler:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
Loading…
Reference in a new issue