[ASBridgedPropertiesTest] Make node retention test more reliable.

This commit is contained in:
Adlai Holler 2016-02-18 18:12:40 -08:00
parent 311c375c4b
commit 0af95c344c

View File

@ -32,6 +32,18 @@
@end @end
@interface ASBridgedPropertiesTestNode : ASDisplayNode
@property (nullable, nonatomic, copy) dispatch_block_t onDealloc;
@end
@implementation ASBridgedPropertiesTestNode
- (void)dealloc {
_onDealloc();
}
@end
@interface ASBridgedPropertiesTests : XCTestCase @interface ASBridgedPropertiesTests : XCTestCase
@end @end
@ -60,10 +72,12 @@ static inline void ASDispatchSyncOnOtherThread(dispatch_block_t block) {
- (void)testThatDirtyNodesAreNotRetained - (void)testThatDirtyNodesAreNotRetained
{ {
ASPendingStateController *ctrl = [ASPendingStateController sharedInstance]; ASPendingStateController *ctrl = [ASPendingStateController sharedInstance];
__weak ASDisplayNode *weakNode = nil; __block BOOL didDealloc = NO;
@autoreleasepool { @autoreleasepool {
__attribute__((objc_precise_lifetime)) ASDisplayNode *node = [ASDisplayNode new]; __attribute__((objc_precise_lifetime)) ASBridgedPropertiesTestNode *node = [ASBridgedPropertiesTestNode new];
weakNode = node; node.onDealloc = ^{
didDealloc = YES;
};
[node view]; [node view];
XCTAssertEqual(node.alpha, 1); XCTAssertEqual(node.alpha, 1);
ASDispatchSyncOnOtherThread(^{ ASDispatchSyncOnOtherThread(^{
@ -71,9 +85,8 @@ static inline void ASDispatchSyncOnOtherThread(dispatch_block_t block) {
}); });
XCTAssertEqual(node.alpha, 1); XCTAssertEqual(node.alpha, 1);
XCTAssert(ctrl.test_isFlushScheduled); XCTAssert(ctrl.test_isFlushScheduled);
XCTAssertNotNil(weakNode);
} }
XCTAssertNil(weakNode); XCTAssertTrue(didDealloc);
} }
- (void)testThatSettingABridgedViewPropertyInBackgroundGetsFlushedOnNextRunLoop - (void)testThatSettingABridgedViewPropertyInBackgroundGetsFlushedOnNextRunLoop