From 8ae6013d0e0996e06780b9ac2505ee39e7ce652b Mon Sep 17 00:00:00 2001 From: Ryan Nystrom Date: Wed, 20 Dec 2017 06:22:18 -0800 Subject: [PATCH] Test fixing double insert crash Summary: Looking at crash logs, the new high-firing crash has 2 item inserts in it. Test deduping the insert. Testing b/c I want to make sure there aren't any weird side effects. Differential Revision: D6605474 fbshipit-source-id: 522120074aed2ed4995104443d48d8254ddb4fec --- CHANGELOG.md | 2 ++ Source/Common/IGListExperiments.h | 2 ++ Source/IGListAdapterUpdater.m | 5 +++++ Tests/IGListAdapterE2ETests.m | 19 +++++++++++++++++++ 4 files changed, 28 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38772e11..f632cc2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,8 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag - Check object type on lookup to prevent crossing types if different objects collide with their identifiers. [Ryan Nystrom](https://github.com/rnystrom) [(#tbd)](https://github.com/Instagram/IGListKit/pull/tbd) +- Testing a fix that removes duplicate item-level updates. [Ryan Nystrom](https://github.com/rnystrom) (tbd) + 3.1.1 ----- diff --git a/Source/Common/IGListExperiments.h b/Source/Common/IGListExperiments.h index 5837aca1..cc61ccaf 100644 --- a/Source/Common/IGListExperiments.h +++ b/Source/Common/IGListExperiments.h @@ -24,6 +24,8 @@ typedef NS_OPTIONS (NSInteger, IGListExperiment) { IGListExperimentReloadDataFallback = 1 << 3, /// Test a faster way to return visible section controllers. IGListExperimentFasterVisibleSectionController = 1 << 4, + /// Test deduping item-level updates. + IGListExperimentDedupeItemUpdates = 1 << 5, }; /** diff --git a/Source/IGListAdapterUpdater.m b/Source/IGListAdapterUpdater.m index 46578664..8901a5f3 100644 --- a/Source/IGListAdapterUpdater.m +++ b/Source/IGListAdapterUpdater.m @@ -309,6 +309,11 @@ void convertReloadToDeleteInsert(NSMutableIndexSet *reloads, [itemDeletes addObjectsFromArray:[reloadDeletePaths allObjects]]; [itemInserts addObjectsFromArray:[reloadInsertPaths allObjects]]; + if (IGListExperimentEnabled(self.experiments, IGListExperimentDedupeItemUpdates)) { + itemDeletes = [[[NSSet setWithArray:itemDeletes] allObjects] mutableCopy]; + itemInserts = [[[NSSet setWithArray:itemInserts] allObjects] mutableCopy]; + } + IGListBatchUpdateData *updateData = [[IGListBatchUpdateData alloc] initWithInsertSections:inserts deleteSections:deletes moveSections:moves diff --git a/Tests/IGListAdapterE2ETests.m b/Tests/IGListAdapterE2ETests.m index 9b6ae0da..bb2d0710 100644 --- a/Tests/IGListAdapterE2ETests.m +++ b/Tests/IGListAdapterE2ETests.m @@ -1786,4 +1786,23 @@ [self waitForExpectationsWithTimeout:30 handler:nil]; } +- (void)test_whenInsertingItemTwice_withDedupeExperiment_thatSecondInsertGetsDropped { + ((IGListAdapterUpdater*)self.updater).experiments = IGListExperimentDedupeItemUpdates; + + IGTestObject *object = genTestObject(@1, @1); + [self setupWithObjects:@[object]]; + + IGTestDelegateController *controller = [self.adapter sectionControllerForObject:self.dataSource.objects.firstObject]; + XCTestExpectation *expectation = genExpectation; + [controller.collectionContext performBatchAnimated:YES updates:^(id _Nonnull batchContext) { + object.value = @2; + [batchContext insertInSectionController:controller atIndexes:[NSIndexSet indexSetWithIndex:0]]; + [batchContext insertInSectionController:controller atIndexes:[NSIndexSet indexSetWithIndex:0]]; + } completion:^(BOOL finished) { + [expectation fulfill]; + }]; + + [self waitForExpectationsWithTimeout:30 handler:nil]; +} + @end