From a18565b8b218db29e709fa811233eb48cfed0fba Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Wed, 11 Oct 2023 22:30:36 -0700 Subject: [PATCH] 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 --- Tests/IGListTransactionTests.m | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Tests/IGListTransactionTests.m b/Tests/IGListTransactionTests.m index 25346051a..91d48c5c4 100644 --- a/Tests/IGListTransactionTests.m +++ b/Tests/IGListTransactionTests.m @@ -167,4 +167,21 @@ - (void)test_withReloadTransaction_thatAllStubbedMethodsNoOpCorrectly { [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