Add coverage to catch inconsistency exception

Summary:
Added a unit test to cover the inconsistency exception catch we added to capture the crashes caused by the new collection view behaviour in iOS 16.4.

The test deliberately puts the collection view state and the model state out of alignment, and then tests that the exception correctly occurs as expected.

Reviewed By: fabiomassimo

Differential Revision: D50072956

fbshipit-source-id: 4097cc0451d55d1a148156c783fe42654821113c
This commit is contained in:
Tim Oliver 2023-10-11 22:30:36 -07:00 committed by Facebook GitHub Bot
parent 2bdbc1201a
commit a18565b8b2

View file

@ -167,4 +167,21 @@
[transaction reloadSections:[NSIndexSet indexSet]];
}
- (void)test_withIncorrectUpdatesState_thatInconsistencyExceptionIsCaught {
_config.allowsBackgroundDiffing = NO;
__weak __typeof__(self) weakSelf = self;
self.applySectionDataBlock = ^(IGListTransitionData *data) {
[weakSelf.collectionView deleteItemsAtIndexPaths:@[[NSIndexPath indexPathWithIndex:0]]];
};
BOOL exceptionWasHandled = NO;
IGListBatchUpdateTransaction *batchUpdateTransaction = [self makeBatchUpdateTransaction];
@try {
[batchUpdateTransaction begin];
} @catch (NSException *exception) {
exceptionWasHandled = YES;
XCTAssertTrue([exception.name isEqualToString:@"NSInternalInconsistencyException"]);
}
XCTAssertTrue(exceptionWasHandled);
}
@end