File tree Expand file tree Collapse file tree 2 files changed +7
-11
lines changed Expand file tree Collapse file tree 2 files changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -16,8 +16,6 @@ abstract class MainDispatcherTestBase: TestBase() {
16
16
17
17
abstract fun isMainThread (): Boolean?
18
18
19
- abstract fun scheduleOnMainQueue (block : () -> Unit )
20
-
21
19
/* * Runs the given block as a test, unless [shouldSkipTesting] indicates that the environment is not suitable. */
22
20
fun runTestOrSkip (block : suspend CoroutineScope .() -> Unit ): TestResult {
23
21
// written as a block body to make the need to return `TestResult` explicit
@@ -170,6 +168,8 @@ abstract class MainDispatcherTestBase: TestBase() {
170
168
}
171
169
172
170
abstract class WithRealTimeDelay : MainDispatcherTestBase () {
171
+ abstract fun scheduleOnMainQueue (block : () -> Unit )
172
+
173
173
/* * Tests that after a delay, the execution gets back to the main thread. */
174
174
@Test
175
175
fun testDelay () = runTestOrSkip {
Original file line number Diff line number Diff line change 4
4
5
5
package kotlinx.coroutines
6
6
7
+ import kotlinx.cinterop.*
7
8
import platform.CoreFoundation.*
8
9
import platform.darwin.*
9
10
import kotlin.coroutines.*
@@ -16,16 +17,11 @@ class MainDispatcherTest : MainDispatcherTestBase.WithRealTimeDelay() {
16
17
// skip if already on the main thread, run blocking doesn't really work well with that
17
18
override fun shouldSkipTesting (): Boolean = isMainThread()
18
19
19
- @Test
20
- fun testDispatchNecessityCheckWithMainImmediateDispatcher () = runTestOrSkip {
21
- val immediate = Dispatchers .Main .immediate
22
- assertTrue(immediate.isDispatchNeeded(EmptyCoroutineContext ))
23
- withContext(Dispatchers .Default ) {
24
- assertTrue(immediate.isDispatchNeeded(EmptyCoroutineContext ))
25
- withContext(Dispatchers .Main ) {
26
- assertFalse(immediate.isDispatchNeeded(EmptyCoroutineContext ))
20
+ override fun scheduleOnMainQueue (block : () -> Unit ) {
21
+ autoreleasepool {
22
+ dispatch_async(dispatch_get_main_queue()) {
23
+ block()
27
24
}
28
- assertTrue(immediate.isDispatchNeeded(EmptyCoroutineContext ))
29
25
}
30
26
}
31
27
}
You can’t perform that action at this time.
0 commit comments