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
This commit is contained in:
Ryan Nystrom 2017-01-10 11:06:05 -08:00 committed by Facebook Github Bot
parent fb4e823870
commit 854846921b

View file

@ -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<IGListSectionType> *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