Add crashing test on KT-41811 (#4437)

This commit is contained in:
Alexander Shabalin
2020-10-12 22:20:43 +03:00
committed by GitHub
parent 9e6031e66a
commit 6c1a482539
3 changed files with 39 additions and 0 deletions
@@ -5,6 +5,8 @@ extern BOOL deallocRetainReleaseDeallocated;
@interface DeallocRetainRelease : NSObject
@end;
extern DeallocRetainRelease* globalDeallocRetainRelease;
@protocol WeakReference
@required
@property (weak) id referent;
@@ -81,3 +81,38 @@ private fun createGarbageDeallocLoadWeak(weakRef: WeakReferenceProtocol) {
assertSame(obj, weakDeallocLoadWeak!!.referent)
}
}
@Test
fun testKT41811WithGlobal() {
// Attempt to make the state predictable:
kotlin.native.internal.GC.collect()
deallocRetainReleaseDeallocated = false
assertFalse(deallocRetainReleaseDeallocated)
autoreleasepool {
{
globalDeallocRetainRelease = object: DeallocRetainRelease() {}
}()
}
assertFalse(deallocRetainReleaseDeallocated)
// Clean up local DeallocRetainRelease on Kotlin side
kotlin.native.internal.GC.collect()
assertFalse(deallocRetainReleaseDeallocated)
// And drop the last reference to DeallocRetainRelease from ObjC global scope.
globalDeallocRetainRelease = null
assertFalse(deallocRetainReleaseDeallocated)
// This will dispose `DeallocRetainRelease` on Kotlin side, which will cause `dealloc`
// on ObjC side, which triggers `retain` and `release` of `self`. If these messages
// were to reach Kotlin side, the `release` would have immediately scheduled the
// second disposal of Kotlin object.
kotlin.native.internal.GC.collect()
assertTrue(deallocRetainReleaseDeallocated)
}
@@ -15,6 +15,8 @@ BOOL deallocRetainReleaseDeallocated = NO;
}
@end;
DeallocRetainRelease* globalDeallocRetainRelease = nil;
@implementation ObjCWeakReference
@end;