forked from TextureGroup/Texture
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix retain cycle with transaction operations (TextureGroup#1429)
Add unit tests that help find cycles. `-testWeakWithSingleOperation` fails without the code fix applied.
- Loading branch information
1 parent
a631803
commit 6b81f5a
Showing
3 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// | ||
// ASTransactionTests.m | ||
// AsyncDisplayKitTests | ||
// | ||
// Created by Greg Bolsinga on 3/26/19. | ||
// Copyright © 2019 Pinterest. All rights reserved. | ||
// | ||
|
||
#import "ASTestCase.h" | ||
#import <AsyncDisplayKit/AsyncDisplayKit.h> | ||
|
||
@interface ASTransactionTests : ASTestCase | ||
|
||
@end | ||
|
||
@implementation ASTransactionTests | ||
|
||
- (void)testWeak | ||
{ | ||
__weak _ASAsyncTransaction* weakTransaction = nil; | ||
@autoreleasepool { | ||
CALayer *layer = [[CALayer alloc] init]; | ||
_ASAsyncTransaction *transaction = layer.asyncdisplaykit_asyncTransaction; | ||
|
||
weakTransaction = transaction; | ||
layer = nil; | ||
} | ||
|
||
// held by main transaction group | ||
XCTAssertNotNil(weakTransaction); | ||
|
||
// run so that transaction group drains. | ||
static NSTimeInterval delay = 0.1; | ||
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:delay]]; | ||
|
||
XCTAssertNil(weakTransaction); | ||
} | ||
|
||
- (void)testWeakWhenCancelled | ||
{ | ||
__weak _ASAsyncTransaction* weakTransaction = nil; | ||
@autoreleasepool { | ||
CALayer *layer = [[CALayer alloc] init]; | ||
_ASAsyncTransaction *transaction = layer.asyncdisplaykit_asyncTransaction; | ||
|
||
weakTransaction = transaction; | ||
|
||
[layer asyncdisplaykit_cancelAsyncTransactions]; | ||
layer = nil; | ||
} | ||
|
||
XCTAssertNil(weakTransaction); | ||
} | ||
|
||
- (void)testWeakWithSingleOperation | ||
{ | ||
__weak _ASAsyncTransaction* weakTransaction = nil; | ||
@autoreleasepool { | ||
CALayer *layer = [[CALayer alloc] init]; | ||
_ASAsyncTransaction *transaction = layer.asyncdisplaykit_asyncTransaction; | ||
|
||
[transaction addOperationWithBlock:^id<NSObject> _Nullable{ | ||
return nil; | ||
} priority:1 | ||
queue:dispatch_get_main_queue() | ||
completion:^(id _Nullable value, BOOL canceled) { | ||
; | ||
}]; | ||
|
||
weakTransaction = transaction; | ||
layer = nil; | ||
} | ||
|
||
// held by main transaction group | ||
XCTAssertNotNil(weakTransaction); | ||
|
||
// run so that transaction group drains. | ||
static NSTimeInterval delay = 0.1; | ||
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:delay]]; | ||
|
||
XCTAssertNil(weakTransaction); | ||
} | ||
|
||
@end |