From 854846921bd47a228672a689cacba8398a7eaa32 Mon Sep 17 00:00:00 2001 From: Ryan Nystrom Date: Tue, 10 Jan 2017 11:06:05 -0800 Subject: [PATCH] Test for section controller retain cycles Summary: Saw our [retain cycle detector](https://github.com/facebook/FBRetainCycleDetector) fire for the `_objectTransitionBlock` in the adapter (t15355965) so I added a test. The test passes, so I don't think that is what's going on, but figured I'd submit the test anyways. - [x] All tests pass. Demo project builds and runs. - [x] I added tests, an experiment, or detailed why my change isn't tested. - [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md) Closes https://github.com/Instagram/IGListKit/pull/401 Differential Revision: D4398534 Pulled By: rnystrom fbshipit-source-id: d5f07a1222c28553dbac66971a90731b2f1c397f --- Tests/IGListAdapterE2ETests.m | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Tests/IGListAdapterE2ETests.m b/Tests/IGListAdapterE2ETests.m index 94042d97..77f0e3c6 100644 --- a/Tests/IGListAdapterE2ETests.m +++ b/Tests/IGListAdapterE2ETests.m @@ -1159,4 +1159,34 @@ [self waitForExpectationsWithTimeout:15 handler:nil]; } +- (void)test_whenQueuingUpdate_withSectionControllerBatchUpdate_thatSectionControllerNotRetained { + __weak id weakSectionController = nil; + @autoreleasepool { + IGListAdapter *adapter = [[IGListAdapter alloc] initWithUpdater:[IGListAdapterUpdater new] viewController:nil workingRangeSize:0]; + IGTestDelegateDataSource *dataSource = [IGTestDelegateDataSource new]; + IGTestObject *object = genTestObject(@1, @2); + dataSource.objects = @[object]; + IGListCollectionView *collectionView = [[IGListCollectionView alloc] initWithFrame:CGRectMake(0, 0, 100, 100) collectionViewLayout:[UICollectionViewFlowLayout new]]; + adapter.collectionView = collectionView; + adapter.dataSource = dataSource; + [collectionView layoutIfNeeded]; + XCTAssertEqual([collectionView numberOfSections], 1); + XCTAssertEqual([collectionView numberOfItemsInSection:0], 2); + + IGListSectionController *section = [adapter sectionControllerForObject:object]; + + [section.collectionContext performBatchAnimated:YES updates:^{ + object.value = @3; + [section.collectionContext insertInSectionController:section atIndexes:[NSIndexSet indexSetWithIndex:0]]; + } completion:^(BOOL finished) {}]; + + dataSource.objects = @[object, genTestObject(@2, @2)]; + [adapter performUpdatesAnimated:YES completion:^(BOOL finished) {}]; + + weakSectionController = section; + XCTAssertNotNil(weakSectionController); + } + XCTAssertNil(weakSectionController); +} + @end