@@ -35,42 +35,45 @@ class ThreadLocalCustomContinuationInterceptorTest : TestBase() {
35
35
override fun equals (other : Any? ) = false
36
36
}
37
37
38
- @Test
38
+ @Test(timeout = 20_000L )
39
39
fun testDefaultDispatcherNoSuspension () = ensureCoroutineContextGCed(Dispatchers .Default , suspend = false )
40
40
41
- @Test
41
+ @Test(timeout = 20_000L )
42
42
fun testDefaultDispatcher () = ensureCoroutineContextGCed(Dispatchers .Default , suspend = true )
43
43
44
44
45
- @Test
45
+ @Test(timeout = 20_000L )
46
46
fun testNonCoroutineDispatcher () = ensureCoroutineContextGCed(
47
47
CustomContinuationInterceptor (Dispatchers .Default ),
48
48
suspend = true
49
49
)
50
50
51
- @Test
51
+ @Test(timeout = 20_000L )
52
52
fun testNonCoroutineDispatcherSuspension () = ensureCoroutineContextGCed(
53
53
CustomContinuationInterceptor (Dispatchers .Default ),
54
54
suspend = false
55
55
)
56
56
57
57
// Note asymmetric equals codepath never goes through the undispatched withContext, thus the separate test case
58
58
59
- @Test
59
+ @Test(timeout = 20_000L )
60
60
fun testNonCoroutineDispatcherAsymmetricEquals () =
61
61
ensureCoroutineContextGCed(
62
62
CustomNeverEqualContinuationInterceptor (Dispatchers .Default ),
63
63
suspend = true
64
64
)
65
65
66
- @Test
66
+ @Test(timeout = 20_000L )
67
67
fun testNonCoroutineDispatcherAsymmetricEqualsSuspension () =
68
68
ensureCoroutineContextGCed(
69
69
CustomNeverEqualContinuationInterceptor (Dispatchers .Default ),
70
70
suspend = false
71
71
)
72
72
73
73
74
+ @Volatile
75
+ private var letThatSinkIn: Any = " What is my purpose? To frag the garbage collctor"
76
+
74
77
private fun ensureCoroutineContextGCed (coroutineContext : CoroutineContext , suspend : Boolean ) {
75
78
runTest {
76
79
lateinit var ref: WeakReference <CoroutineName >
@@ -85,11 +88,10 @@ class ThreadLocalCustomContinuationInterceptorTest : TestBase() {
85
88
}
86
89
job.join()
87
90
88
- // Twice is enough to ensure
89
- System .gc()
90
- System .gc( )
91
- assertNull(ref.get())
91
+ while (ref.get() != null ) {
92
+ System .gc()
93
+ letThatSinkIn = LongArray ( 1024 * 1024 )
94
+ }
92
95
}
93
96
}
94
-
95
97
}
0 commit comments