MPP: More common tests, using kotlin.test.assertTrue & runTest dsl
diff --git a/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonAsyncLazyTest.kt b/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonAsyncLazyTest.kt
index 3f319a6..a56084d 100644
--- a/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonAsyncLazyTest.kt
+++ b/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonAsyncLazyTest.kt
@@ -29,11 +29,11 @@
             42
         }
         expect(2)
-        check(!d.isActive && !d.isCompleted)
-        check(d.await() == 42)
-        check(!d.isActive && d.isCompleted && !d.isCompletedExceptionally)
+        assertTrue(!d.isActive && !d.isCompleted)
+        assertTrue(d.await() == 42)
+        assertTrue(!d.isActive && d.isCompleted && !d.isCompletedExceptionally)
         expect(4)
-        check(d.await() == 42) // second await -- same result
+        assertTrue(d.await() == 42) // second await -- same result
         finish(5)
     }
 
@@ -47,11 +47,11 @@
             42
         }
         expect(2)
-        check(!d.isActive && !d.isCompleted)
-        check(d.await() == 42)
-        check(!d.isActive && d.isCompleted && !d.isCompletedExceptionally)
+        assertTrue(!d.isActive && !d.isCompleted)
+        assertTrue(d.await() == 42)
+        assertTrue(!d.isActive && d.isCompleted && !d.isCompletedExceptionally)
         expect(5)
-        check(d.await() == 42) // second await -- same result
+        assertTrue(d.await() == 42) // second await -- same result
         finish(6)
     }
 
@@ -63,22 +63,22 @@
             42
         }
         expect(2)
-        check(!d.isActive && !d.isCompleted)
+        assertTrue(!d.isActive && !d.isCompleted)
         launch(coroutineContext) { // see how it looks from another coroutine
             expect(4)
-            check(!d.isActive && !d.isCompleted)
+            assertTrue(!d.isActive && !d.isCompleted)
             yield() // yield back to main
             expect(6)
-            check(d.isActive && !d.isCompleted) // implicitly started by main's await
+            assertTrue(d.isActive && !d.isCompleted) // implicitly started by main's await
             yield() // yield to d
         }
         expect(3)
-        check(!d.isActive && !d.isCompleted)
+        assertTrue(!d.isActive && !d.isCompleted)
         yield() // yield to second child (lazy async is not computing yet)
         expect(5)
-        check(!d.isActive && !d.isCompleted)
-        check(d.await() == 42) // starts computing
-        check(!d.isActive && d.isCompleted && !d.isCompletedExceptionally)
+        assertTrue(!d.isActive && !d.isCompleted)
+        assertTrue(d.await() == 42) // starts computing
+        assertTrue(!d.isActive && d.isCompleted && !d.isCompletedExceptionally)
         finish(8)
     }
 
@@ -92,7 +92,7 @@
             throw TestException()
         }
         expect(2)
-        check(!d.isActive && !d.isCompleted)
+        assertTrue(!d.isActive && !d.isCompleted)
         d.await() // will throw IOException
     }
 
@@ -108,7 +108,7 @@
             throw TestException()
         }
         expect(2)
-        check(!d.isActive && !d.isCompleted)
+        assertTrue(!d.isActive && !d.isCompleted)
         d.await() // will throw IOException
     }
 
@@ -120,11 +120,11 @@
             throw TestException()
         }
         expect(2)
-        check(!d.isActive && !d.isCompleted)
+        assertTrue(!d.isActive && !d.isCompleted)
         try {
             d.await() // will throw IOException
         } catch (e: TestException) {
-            check(!d.isActive && d.isCompleted && d.isCompletedExceptionally && !d.isCancelled)
+            assertTrue(!d.isActive && d.isCompleted && d.isCompletedExceptionally && !d.isCancelled)
             expect(4)
         }
         finish(5)
@@ -138,15 +138,15 @@
             42
         }
         expect(2)
-        check(!d.isActive && !d.isCompleted)
-        check(d.start())
-        check(d.isActive && !d.isCompleted)
+        assertTrue(!d.isActive && !d.isCompleted)
+        assertTrue(d.start())
+        assertTrue(d.isActive && !d.isCompleted)
         expect(3)
-        check(!d.start())
+        assertTrue(!d.start())
         yield() // yield to started coroutine
-        check(!d.isActive && d.isCompleted && !d.isCompletedExceptionally) // and it finishes
+        assertTrue(!d.isActive && d.isCompleted && !d.isCompletedExceptionally) // and it finishes
         expect(5)
-        check(d.await() == 42) // await sees result
+        assertTrue(d.await() == 42) // await sees result
         finish(6)
     }
 
@@ -160,13 +160,13 @@
             42
         }
         expect(2)
-        check(!d.isActive && !d.isCompleted)
-        check(d.cancel())
-        check(!d.isActive && d.isCompleted && d.isCompletedExceptionally && d.isCancelled)
-        check(!d.cancel())
-        check(!d.start())
+        assertTrue(!d.isActive && !d.isCompleted)
+        assertTrue(d.cancel())
+        assertTrue(!d.isActive && d.isCompleted && d.isCompletedExceptionally && d.isCancelled)
+        assertTrue(!d.cancel())
+        assertTrue(!d.start())
         finish(3)
-        check(d.await() == 42) // await shall throw CancellationException
+        assertTrue(d.await() == 42) // await shall throw CancellationException
         expectUnreached()
     }
 
@@ -182,19 +182,19 @@
             42
         }
         expect(2)
-        check(!d.isActive && !d.isCompleted && !d.isCancelled)
-        check(d.start())
-        check(d.isActive && !d.isCompleted && !d.isCancelled)
+        assertTrue(!d.isActive && !d.isCompleted && !d.isCancelled)
+        assertTrue(d.start())
+        assertTrue(d.isActive && !d.isCompleted && !d.isCancelled)
         expect(3)
         yield() // yield to d
         expect(5)
-        check(d.isActive && !d.isCompleted && !d.isCancelled)
-        check(d.cancel())
-        check(!d.isActive && !d.isCompletedExceptionally && d.isCancelled) // cancelling !
-        check(!d.cancel())
-        check(!d.isActive && !d.isCompletedExceptionally && d.isCancelled) // still cancelling
+        assertTrue(d.isActive && !d.isCompleted && !d.isCancelled)
+        assertTrue(d.cancel())
+        assertTrue(!d.isActive && !d.isCompletedExceptionally && d.isCancelled) // cancelling !
+        assertTrue(!d.cancel())
+        assertTrue(!d.isActive && !d.isCompletedExceptionally && d.isCancelled) // still cancelling
         finish(6)
-        check(d.await() == 42) // await shall throw CancellationException
+        assertTrue(d.await() == 42) // await shall throw CancellationException
         expectUnreached()
     }
 
diff --git a/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonAsyncTest.kt b/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonAsyncTest.kt
index 128b8b7..f933f72 100644
--- a/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonAsyncTest.kt
+++ b/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonAsyncTest.kt
@@ -29,11 +29,11 @@
             42
         }
         expect(2)
-        check(d.isActive)
-        check(d.await() == 42)
-        check(!d.isActive)
+        assertTrue(d.isActive)
+        assertTrue(d.await() == 42)
+        assertTrue(!d.isActive)
         expect(4)
-        check(d.await() == 42) // second await -- same result
+        assertTrue(d.await() == 42) // second await -- same result
         finish(5)
     }
 
@@ -45,8 +45,8 @@
             42
         }
         expect(3)
-        check(!d.isActive)
-        check(d.await() == 42)
+        assertTrue(!d.isActive)
+        assertTrue(d.await() == 42)
         finish(4)
     }
 
@@ -90,13 +90,13 @@
         expect(2)
         launch(coroutineContext) {
             expect(6)
-            check(d.await() == 42)
+            assertTrue(d.await() == 42)
             expect(11)
         }
         expect(3)
         launch(coroutineContext) {
             expect(7)
-            check(d.await() == 42)
+            assertTrue(d.await() == 42)
             expect(12)
         }
         expect(4)
diff --git a/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonAtomicCancellationTest.kt b/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonAtomicCancellationTest.kt
new file mode 100644
index 0000000..65be69a
--- /dev/null
+++ b/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonAtomicCancellationTest.kt
@@ -0,0 +1,82 @@
+package kotlinx.coroutines.experimental
+
+import kotlin.test.*
+
+class CommonAtomicCancellationTest : TestBase() {
+    @Test
+    fun testCancellableLaunch() = runBlocking {
+        expect(1)
+        val job = launch(coroutineContext) {
+            expectUnreached() // will get cancelled before start
+        }
+        expect(2)
+        job.cancel()
+        finish(3)
+    }
+
+    @Test
+    fun testAtomicLaunch() = runBlocking {
+        expect(1)
+        val job = launch(coroutineContext, start = CoroutineStart.ATOMIC) {
+            finish(4) // will execute even after it was cancelled
+        }
+        expect(2)
+        job.cancel()
+        expect(3)
+    }
+
+    @Test
+    fun testDeferredAwaitCancellable() = runBlocking {
+        expect(1)
+        val deferred = async(coroutineContext) { // deferred, not yet complete
+            expect(4)
+            "OK"
+        }
+        assertEquals(false, deferred.isCompleted)
+        var job: Job? = null
+        launch(coroutineContext) { // will cancel job as soon as deferred completes
+            expect(5)
+            assertEquals(true, deferred.isCompleted)
+            job!!.cancel()
+        }
+        job = launch(coroutineContext, start = CoroutineStart.UNDISPATCHED) {
+            expect(2)
+            try {
+                deferred.await() // suspends
+                expectUnreached() // will not execute -- cancelled while dispatched
+            } finally {
+                finish(7) // but will execute finally blocks
+            }
+        }
+        expect(3) // continues to execute when job suspends
+        yield() // to deferred & canceller
+        expect(6)
+    }
+
+    @Test
+    fun testJobJoinCancellable() = runBlocking {
+        expect(1)
+        val jobToJoin = launch(coroutineContext) { // not yet complete
+            expect(4)
+        }
+        assertEquals(false, jobToJoin.isCompleted)
+        var job: Job? = null
+        launch(coroutineContext) { // will cancel job as soon as jobToJoin completes
+            expect(5)
+            assertEquals(true, jobToJoin.isCompleted)
+            job!!.cancel()
+        }
+        job = launch(coroutineContext, start = CoroutineStart.UNDISPATCHED) {
+            expect(2)
+            try {
+                jobToJoin.join() // suspends
+                expectUnreached() // will not execute -- cancelled while dispatched
+            } finally {
+                finish(7) // but will execute finally blocks
+            }
+        }
+        expect(3) // continues to execute when job suspends
+        yield() // to jobToJoin & canceller
+        expect(6)
+    }
+}
\ No newline at end of file
diff --git a/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonCompletableDeferredTest.kt b/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonCompletableDeferredTest.kt
index f3e79e8..de7aed3 100644
--- a/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonCompletableDeferredTest.kt
+++ b/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonCompletableDeferredTest.kt
@@ -157,7 +157,7 @@
     }
 
     @Test
-    fun testAwait() = runBlocking {
+    fun testAwait() = runTest {
         expect(1)
         val c = CompletableDeferred<String>()
         launch(coroutineContext, CoroutineStart.UNDISPATCHED) {
diff --git a/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonCoroutineExceptionHandlerTest.kt b/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonCoroutineExceptionHandlerTest.kt
index 098c0a0..84677cc 100644
--- a/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonCoroutineExceptionHandlerTest.kt
+++ b/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonCoroutineExceptionHandlerTest.kt
@@ -4,7 +4,7 @@
 
 class CommonCoroutineExceptionHandlerTest : TestBase() {
     @Test
-    fun testCoroutineExceptionHandlerCreator() = runBlocking {
+    fun testCoroutineExceptionHandlerCreator() = runTest {
         expect(1)
         var coroutineException: Throwable? = null
         val handler = CoroutineExceptionHandler { _, ex ->
@@ -17,7 +17,7 @@
         expect(2)
         job.join()
         finish(4)
-        check(coroutineException is TestException)
+        assertTrue(coroutineException is TestException)
     }
 
     private class TestException: RuntimeException()
diff --git a/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonCoroutinesTest.kt b/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonCoroutinesTest.kt
index 1d736db..b94ca92 100644
--- a/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonCoroutinesTest.kt
+++ b/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonCoroutinesTest.kt
@@ -43,9 +43,9 @@
             expect(4)
         }
         expect(2)
-        check(job.isActive && !job.isCompleted)
+        assertTrue(job.isActive && !job.isCompleted)
         job.join()
-        check(!job.isActive && job.isCompleted)
+        assertTrue(!job.isActive && job.isCompleted)
         finish(5)
     }
 
@@ -58,9 +58,9 @@
             expect(4)
         }
         expect(3)
-        check(job.isActive && !job.isCompleted)
+        assertTrue(job.isActive && !job.isCompleted)
         job.join()
-        check(!job.isActive && job.isCompleted)
+        assertTrue(!job.isActive && job.isCompleted)
         finish(5)
     }
 
@@ -218,15 +218,15 @@
         expect(2)
         yield() // to job
         expect(4)
-        check(job.isActive && !job.isCompleted && !job.isCancelled)
-        check(job.cancel())  // cancels job
+        assertTrue(job.isActive && !job.isCompleted && !job.isCancelled)
+        assertTrue(job.cancel())  // cancels job
         expect(5) // still here
-        check(!job.isActive && !job.isCompleted && job.isCancelled)
-        check(!job.cancel()) // second attempt returns false
+        assertTrue(!job.isActive && !job.isCompleted && job.isCancelled)
+        assertTrue(!job.cancel()) // second attempt returns false
         expect(6) // we're still here
         job.join() // join the job, let job complete its "finally" section
         expect(8)
-        check(!job.isActive && job.isCompleted && job.isCancelled)
+        assertTrue(!job.isActive && job.isCompleted && job.isCancelled)
         finish(9)
     }
 
@@ -264,8 +264,8 @@
             job.cancelAndJoin() // join should crash on child's exception but it will be wrapped into JobCancellationException
         } catch (e: Throwable) {
             e as JobCancellationException // type assertion
-            check(e.cause is TestException)
-            check(e.job === coroutineContext[Job])
+            assertTrue(e.cause is TestException)
+            assertTrue(e.job === coroutineContext[Job])
             throw e
         }
         expectUnreached()
@@ -304,7 +304,7 @@
         parent.cancelChildren()
         expect(4)
         parent.joinChildren() // will yield to child
-        check(parent.isActive) // make sure it did not cancel parent
+        assertTrue(parent.isActive) // make sure it did not cancel parent
         finish(6)
     }
 
@@ -335,6 +335,25 @@
         finish(8)
     }
 
+    @Test
+    fun testNotCancellableChildWithExceptionCancelled() = runTest(
+        expected = { it is TestException }
+    ) {
+        expect(1)
+        // CoroutineStart.ATOMIC makes sure it will not get cancelled for it starts executing
+        val d = async(coroutineContext, start = CoroutineStart.ATOMIC) {
+            finish(4)
+            throwTestException() // will throw
+            expectUnreached()
+        }
+        expect(2)
+        // now cancel with some other exception
+        d.cancel(IllegalArgumentException())
+        // now await to see how it got crashed -- IAE should have been suppressed by TestException
+        expect(3)
+        d.await()
+    }
+
     private fun throwTestException() { throw TestException() }
 
     private class TestException : Exception {
diff --git a/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonJobTest.kt b/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonJobTest.kt
index cd4fb29..b699a0f 100644
--- a/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonJobTest.kt
+++ b/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonJobTest.kt
@@ -6,9 +6,9 @@
     @Test
     fun testState() {
         val job = Job()
-        check(job.isActive)
+        assertTrue(job.isActive)
         job.cancel()
-        check(!job.isActive)
+        assertTrue(!job.isActive)
     }
 
     @Test
@@ -16,15 +16,15 @@
         val job = Job()
         var fireCount = 0
         job.invokeOnCompletion { fireCount++ }
-        check(job.isActive)
+        assertTrue(job.isActive)
         assertEquals(0, fireCount)
         // cancel once
         job.cancel()
-        check(!job.isActive)
+        assertTrue(!job.isActive)
         assertEquals(1, fireCount)
         // cancel again
         job.cancel()
-        check(!job.isActive)
+        assertTrue(!job.isActive)
         assertEquals(1, fireCount)
     }
 
@@ -34,15 +34,15 @@
         val n = 100 * stressTestMultiplier
         val fireCount = IntArray(n)
         for (i in 0 until n) job.invokeOnCompletion { fireCount[i]++ }
-        check(job.isActive)
+        assertTrue(job.isActive)
         for (i in 0 until n) assertEquals(0, fireCount[i])
         // cancel once
         job.cancel()
-        check(!job.isActive)
+        assertTrue(!job.isActive)
         for (i in 0 until n) assertEquals(1, fireCount[i])
         // cancel again
         job.cancel()
-        check(!job.isActive)
+        assertTrue(!job.isActive)
         for (i in 0 until n) assertEquals(1, fireCount[i])
     }
 
@@ -58,15 +58,15 @@
                 registration!!.dispose()
             }
         }
-        check(job.isActive)
+        assertTrue(job.isActive)
         for (i in 0 until n) assertEquals(0, fireCount[i])
         // cancel once
         job.cancel()
-        check(!job.isActive)
+        assertTrue(!job.isActive)
         for (i in 0 until n) assertEquals(1, fireCount[i])
         // cancel again
         job.cancel()
-        check(!job.isActive)
+        assertTrue(!job.isActive)
         for (i in 0 until n) assertEquals(1, fireCount[i])
     }
 
@@ -76,12 +76,12 @@
         val n = 100 * stressTestMultiplier
         val fireCount = IntArray(n)
         val registrations = Array<DisposableHandle>(n) { i -> job.invokeOnCompletion { fireCount[i]++ } }
-        check(job.isActive)
+        assertTrue(job.isActive)
         fun unreg(i: Int) = i % 4 <= 1
         for (i in 0 until n) if (unreg(i)) registrations[i].dispose()
         for (i in 0 until n) assertEquals(0, fireCount[i])
         job.cancel()
-        check(!job.isActive)
+        assertTrue(!job.isActive)
         for (i in 0 until n) assertEquals(if (unreg(i)) 0 else 1, fireCount[i])
     }
 
@@ -95,22 +95,22 @@
             fireCount[i]++
             throw TestException()
         }
-        check(job.isActive)
+        assertTrue(job.isActive)
         for (i in 0 until n) assertEquals(0, fireCount[i])
         val tryCancel = Try<Unit> { job.cancel() }
-        check(!job.isActive)
+        assertTrue(!job.isActive)
         for (i in 0 until n) assertEquals(1, fireCount[i])
-        check(tryCancel.exception is CompletionHandlerException)
-        check(tryCancel.exception!!.cause is TestException)
+        assertTrue(tryCancel.exception is CompletionHandlerException)
+        assertTrue(tryCancel.exception!!.cause is TestException)
     }
 
     @Test
     fun testCancelledParent() {
         val parent = Job()
         parent.cancel()
-        check(!parent.isActive)
+        assertTrue(!parent.isActive)
         val child = Job(parent)
-        check(!child.isActive)
+        assertTrue(!child.isActive)
     }
 
     @Test
diff --git a/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonLaunchLazyTest.kt b/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonLaunchLazyTest.kt
index 22fe3fd..29651f5 100644
--- a/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonLaunchLazyTest.kt
+++ b/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonLaunchLazyTest.kt
@@ -30,9 +30,9 @@
         expect(2)
         yield() // does nothing, was not started yet
         expect(3)
-        check(!job.isActive && !job.isCompleted)
+        assertTrue(!job.isActive && !job.isCompleted)
         job.join()
-        check(!job.isActive && job.isCompleted)
+        assertTrue(!job.isActive && job.isCompleted)
         finish(6)
     }
 
@@ -47,17 +47,17 @@
         expect(2)
         yield() // does nothing, was not started yet
         expect(3)
-        check(!job.isActive && !job.isCompleted)
-        check(job.start())
-        check(job.isActive && !job.isCompleted)
-        check(!job.start()) // start again -- does nothing
-        check(job.isActive && !job.isCompleted)
+        assertTrue(!job.isActive && !job.isCompleted)
+        assertTrue(job.start())
+        assertTrue(job.isActive && !job.isCompleted)
+        assertTrue(!job.start()) // start again -- does nothing
+        assertTrue(job.isActive && !job.isCompleted)
         expect(4)
         yield() // now yield to started coroutine
         expect(6)
-        check(job.isActive && !job.isCompleted)
+        assertTrue(job.isActive && !job.isCompleted)
         yield() // yield again
-        check(!job.isActive && job.isCompleted) // it completes this time
+        assertTrue(!job.isActive && job.isCompleted) // it completes this time
         expect(8)
         job.join() // immediately returns
         finish(9)
diff --git a/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonWithContextTest.kt b/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonWithContextTest.kt
index fb75b57..24b922a 100644
--- a/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonWithContextTest.kt
+++ b/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonWithContextTest.kt
@@ -144,7 +144,7 @@
             } catch (e: Throwable) {
                 expect(7)
                 // make sure IOException, not CancellationException is thrown!
-                check(e is TestException)
+                assertTrue(e is TestException)
             }
         }
         expect(2)
diff --git a/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonWithTimeoutOrNullTest.kt b/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonWithTimeoutOrNullTest.kt
new file mode 100644
index 0000000..60f5bd8
--- /dev/null
+++ b/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonWithTimeoutOrNullTest.kt
@@ -0,0 +1,113 @@
+
+@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913
+
+package kotlinx.coroutines.experimental
+
+import kotlin.test.*
+
+class CommonWithTimeoutOrNullTest : TestBase() {
+    /**
+     * Tests a case of no timeout and no suspension inside.
+     */
+    @Test
+    fun testBasicNoSuspend() = runTest {
+        expect(1)
+        val result = withTimeoutOrNull(10_000) {
+            expect(2)
+            "OK"
+        }
+        assertEquals("OK", result)
+        finish(3)
+    }
+
+    /**
+     * Tests a case of no timeout and one suspension inside.
+     */
+    @Test
+    fun testBasicSuspend() = runTest {
+        expect(1)
+        val result = withTimeoutOrNull(10_000) {
+            expect(2)
+            yield()
+            expect(3)
+            "OK"
+        }
+        assertEquals("OK", result)
+        finish(4)
+    }
+
+    /**
+     * Tests property dispatching of `withTimeoutOrNull` blocks
+     */
+    @Test
+    fun testDispatch() = runTest {
+        expect(1)
+        launch(coroutineContext) {
+            expect(4)
+            yield() // back to main
+            expect(7)
+        }
+        expect(2)
+        // test that it does not yield to the above job when started
+        val result = withTimeoutOrNull(1000) {
+            expect(3)
+            yield() // yield only now
+            expect(5)
+            "OK"
+        }
+        assertEquals("OK", result)
+        expect(6)
+        yield() // back to launch
+        finish(8)
+    }
+
+    /**
+     * Tests that a 100% CPU-consuming loop will react on timeout if it has yields.
+     */
+    @Test
+    fun testYieldBlockingWithTimeout() = runTest {
+        expect(1)
+        val result = withTimeoutOrNull(100) {
+            while (true) {
+                yield()
+            }
+        }
+        assertEquals(null, result)
+        finish(2)
+    }
+
+    @Test
+    fun testInnerTimeoutTest() = runTest(
+        expected = { it is CancellationException }
+    ) {
+        withTimeoutOrNull(200) {
+            withTimeout(100) {
+                while (true) {
+                    yield()
+                }
+            }
+            expectUnreached() // will timeout
+        }
+        expectUnreached() // will timeout
+    }
+
+    @Test
+    fun testOuterTimeoutTest() = runTest {
+        var counter = 0
+        val result = withTimeoutOrNull(250) {
+            while (true) {
+                val inner = withTimeoutOrNull(100) {
+                    while (true) {
+                        yield()
+                    }
+                }
+                assertEquals(null, inner)
+                counter++
+            }
+        }
+        assertEquals(null, result)
+        // under load counter may be equal to 1, so the check is lenient here
+        println("Executed: $counter times")
+        check(counter in 1..2)
+    }
+}
\ No newline at end of file
diff --git a/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonWithTimeoutTest.kt b/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonWithTimeoutTest.kt
new file mode 100644
index 0000000..9ee34ec
--- /dev/null
+++ b/common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonWithTimeoutTest.kt
@@ -0,0 +1,97 @@
+
+@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913
+
+package kotlinx.coroutines.experimental
+
+import kotlin.test.*
+
+class CommonWithTimeoutTest : TestBase() {
+    /**
+     * Tests a case of no timeout and no suspension inside.
+     */
+    @Test
+    fun testBasicNoSuspend() = runTest {
+        expect(1)
+        val result = withTimeout(10_000) {
+            expect(2)
+            "OK"
+        }
+        assertEquals("OK", result)
+        finish(3)
+    }
+
+    /**
+     * Tests a case of no timeout and one suspension inside.
+     */
+    @Test
+    fun testBasicSuspend() = runTest {
+        expect(1)
+        val result = withTimeout(10_000) {
+            expect(2)
+            yield()
+            expect(3)
+            "OK"
+        }
+        assertEquals("OK", result)
+        finish(4)
+    }
+
+    /**
+     * Tests proper dispatching of `withTimeout` blocks
+     */
+    @Test
+    fun testDispatch() = runTest {
+        expect(1)
+        launch(coroutineContext) {
+            expect(4)
+            yield() // back to main
+            expect(7)
+        }
+        expect(2)
+        // test that it does not yield to the above job when started
+        val result = withTimeout(1000) {
+            expect(3)
+            yield() // yield only now
+            expect(5)
+            "OK"
+        }
+        assertEquals("OK", result)
+        expect(6)
+        yield() // back to launch
+        finish(8)
+    }
+
+
+    /**
+     * Tests that a 100% CPU-consuming loop will react on timeout if it has yields.
+     */
+    @Test
+    fun testYieldBlockingWithTimeout() = runTest(
+        expected = { it is CancellationException }
+    ) {
+        withTimeout(100) {
+            while (true) {
+                yield()
+            }
+        }
+    }
+
+    /**
+     * Tests that [withTimeout] waits for children coroutines to complete.
+     */
+    @Test
+    fun testWithTimeoutChildWait() = runTest {
+        expect(1)
+        withTimeout(100) {
+            expect(2)
+            // launch child with timeout
+            launch(coroutineContext) {
+                expect(4)
+            }
+            expect(3)
+            // now will wait for child before returning
+        }
+        finish(5)
+    }
+}
+
diff --git a/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/AtomicCancellationTest.kt b/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/AtomicCancellationTest.kt
index 14b2b53..6d43cc1 100644
--- a/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/AtomicCancellationTest.kt
+++ b/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/AtomicCancellationTest.kt
@@ -19,33 +19,9 @@
 import kotlinx.coroutines.experimental.channels.Channel
 import kotlinx.coroutines.experimental.selects.select
 import kotlinx.coroutines.experimental.sync.Mutex
-import org.hamcrest.core.IsEqual
-import org.junit.Assert.assertThat
-import org.junit.Test
+import kotlin.test.*
 
-class AtomicCancellationTest: TestBase() {
-    @Test
-    fun testCancellableLaunch() = runBlocking {
-        expect(1)
-        val job = launch(coroutineContext) {
-            expectUnreached() // will get cancelled before start
-        }
-        expect(2)
-        job.cancel()
-        finish(3)
-    }
-
-    @Test
-    fun testAtomicLaunch() = runBlocking {
-        expect(1)
-        val job = launch(coroutineContext, start = CoroutineStart.ATOMIC) {
-            finish(4) // will execute even after it was cancelled
-        }
-        expect(2)
-        job.cancel()
-        expect(3)
-    }
-
+class AtomicCancellationTest : TestBase() {
     @Test
     fun testLockAtomicCancel() = runBlocking {
         expect(1)
@@ -74,7 +50,7 @@
                     "OK"
                 }
             }
-            assertThat(result, IsEqual("OK"))
+            assertEquals("OK", result)
             expect(5) // should execute despite cancellation
         }
         expect(3)
@@ -94,7 +70,7 @@
             expect(4) // should execute despite cancellation
         }
         expect(3)
-        assertThat(channel.receive(), IsEqual(42)) // will schedule sender for further execution
+        assertEquals(42, channel.receive()) // will schedule sender for further execution
         job.cancel() // cancel the job next
         yield() // now yield
         finish(5)
@@ -112,11 +88,11 @@
                     "OK"
                 }
             }
-            assertThat(result, IsEqual("OK"))
+            assertEquals("OK", result)
             expect(5) // should execute despite cancellation
         }
         expect(3)
-        assertThat(channel.receive(), IsEqual(42)) // will schedule sender for further execution
+        assertEquals(42, channel.receive()) // will schedule sender for further execution
         job.cancel() // cancel the job next
         yield() // now yield
         finish(6)
@@ -128,7 +104,7 @@
         val channel = Channel<Int>()
         val job = launch(coroutineContext, start = CoroutineStart.UNDISPATCHED) {
             expect(2)
-            assertThat(channel.receive(), IsEqual(42)) // suspends
+            assertEquals(42, channel.receive()) // suspends
             expect(4) // should execute despite cancellation
         }
         expect(3)
@@ -146,12 +122,12 @@
             expect(2)
             val result = select<String> { // suspends
                 channel.onReceive {
-                    assertThat(it, IsEqual(42))
+                    assertEquals(42, it)
                     expect(4)
                     "OK"
                 }
             }
-            assertThat(result, IsEqual("OK"))
+            assertEquals("OK", result)
             expect(5) // should execute despite cancellation
         }
         expect(3)
@@ -162,45 +138,17 @@
     }
 
     @Test
-    fun testDeferredAwaitCancellable() = runBlocking {
-        expect(1)
-        val deferred = async(coroutineContext) { // deferred, not yet complete
-            expect(4)
-            "OK"
-        }
-        assertThat(deferred.isCompleted, IsEqual(false))
-        var job: Job? = null
-        launch(coroutineContext) { // will cancel job as soon as deferred completes
-            expect(5)
-            assertThat(deferred.isCompleted, IsEqual(true))
-            job!!.cancel()
-        }
-        job = launch(coroutineContext, start = CoroutineStart.UNDISPATCHED) {
-            expect(2)
-            try {
-                deferred.await() // suspends
-                expectUnreached() // will not execute -- cancelled while dispatched
-            } finally {
-                finish(7) // but will execute finally blocks
-            }
-        }
-        expect(3) // continues to execute when job suspends
-        yield() // to deferred & canceller
-        expect(6)
-    }
-
-    @Test
     fun testSelectDeferredAwaitCancellable() = runBlocking {
         expect(1)
         val deferred = async(coroutineContext) { // deferred, not yet complete
             expect(4)
             "OK"
         }
-        assertThat(deferred.isCompleted, IsEqual(false))
+        assertEquals(false, deferred.isCompleted)
         var job: Job? = null
         launch(coroutineContext) { // will cancel job as soon as deferred completes
             expect(5)
-            assertThat(deferred.isCompleted, IsEqual(true))
+            assertEquals(true, deferred.isCompleted)
             job!!.cancel()
         }
         job = launch(coroutineContext, start = CoroutineStart.UNDISPATCHED) {
@@ -220,43 +168,16 @@
     }
 
     @Test
-    fun testJobJoinCancellable() = runBlocking {
-        expect(1)
-        val jobToJoin = launch(coroutineContext) { // not yet complete
-            expect(4)
-        }
-        assertThat(jobToJoin.isCompleted, IsEqual(false))
-        var job: Job? = null
-        launch(coroutineContext) { // will cancel job as soon as jobToJoin completes
-            expect(5)
-            assertThat(jobToJoin.isCompleted, IsEqual(true))
-            job!!.cancel()
-        }
-        job = launch(coroutineContext, start = CoroutineStart.UNDISPATCHED) {
-            expect(2)
-            try {
-                jobToJoin.join() // suspends
-                expectUnreached() // will not execute -- cancelled while dispatched
-            } finally {
-                finish(7) // but will execute finally blocks
-            }
-        }
-        expect(3) // continues to execute when job suspends
-        yield() // to jobToJoin & canceller
-        expect(6)
-    }
-
-    @Test
     fun testSelectJobJoinCancellable() = runBlocking {
         expect(1)
         val jobToJoin = launch(coroutineContext) { // not yet complete
             expect(4)
         }
-        assertThat(jobToJoin.isCompleted, IsEqual(false))
+        assertEquals(false, jobToJoin.isCompleted)
         var job: Job? = null
         launch(coroutineContext) { // will cancel job as soon as jobToJoin completes
             expect(5)
-            assertThat(jobToJoin.isCompleted, IsEqual(true))
+            assertEquals(true, jobToJoin.isCompleted)
             job!!.cancel()
         }
         job = launch(coroutineContext, start = CoroutineStart.UNDISPATCHED) {
@@ -274,6 +195,4 @@
         yield() // to jobToJoin & canceller
         expect(6)
     }
-
-
 }
\ No newline at end of file
diff --git a/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/CoroutinesTest.kt b/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/CoroutinesTest.kt
index b9cc888..29a03e0 100644
--- a/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/CoroutinesTest.kt
+++ b/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/CoroutinesTest.kt
@@ -1,6 +1,6 @@
 package kotlinx.coroutines.experimental
 
-import org.junit.Test
+import kotlin.test.*
 
 class CoroutinesTest : TestBase() {
     @Test
@@ -18,25 +18,6 @@
     }
 
     @Test
-    fun testNotCancellableChildWithExceptionCancelled() = runTest(
-        expected = { it is TestException }
-    ) {
-        expect(1)
-        // CoroutineStart.ATOMIC makes sure it will not get cancelled for it starts executing
-        val d = async(coroutineContext, start = CoroutineStart.ATOMIC) {
-            finish(4)
-            throwTestException() // will throw
-            expectUnreached()
-        }
-        expect(2)
-        // now cancel with some other exception
-        d.cancel(IllegalArgumentException())
-        // now await to see how it got crashed -- IAE should have been suppressed by TestException
-        expect(3)
-        d.await()
-    }
-
-    @Test
     fun testCancelManyCompletedAttachedChildren() = runTest {
         val parent = launch(coroutineContext) { /* do nothing */ }
         val n = 10_000 * stressTestMultiplier
@@ -51,8 +32,5 @@
 
     private fun throwTestException(): Unit = throw TestException()
 
-    private class TestException : Exception {
-        constructor(message: String): super(message)
-        constructor(): super()
-    }
+    private class TestException() : Exception()
 }
\ No newline at end of file
diff --git a/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/WithContextTest.kt b/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/WithContextTest.kt
index 29f240e..ee26c07 100644
--- a/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/WithContextTest.kt
+++ b/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/WithContextTest.kt
@@ -16,9 +16,7 @@
 
 package kotlinx.coroutines.experimental
 
-import org.hamcrest.MatcherAssert.assertThat
-import org.hamcrest.core.IsEqual
-import org.junit.Test
+import kotlin.test.*
 
 class WithContextTest : TestBase() {
     @Test
@@ -28,7 +26,7 @@
             expect(2)
             "OK"
         }
-        assertThat(result, IsEqual("OK"))
+        assertEquals("OK", result)
         finish(3)
     }
 
@@ -41,7 +39,7 @@
             expect(3)
             "OK"
         }
-        assertThat(result, IsEqual("OK"))
+        assertEquals("OK", result)
         finish(4)
     }
 }
\ No newline at end of file
diff --git a/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/WithTimeoutOrNullTest.kt b/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/WithTimeoutOrNullTest.kt
index e4619b8..6c43f76 100644
--- a/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/WithTimeoutOrNullTest.kt
+++ b/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/WithTimeoutOrNullTest.kt
@@ -16,68 +16,9 @@
 
 package kotlinx.coroutines.experimental
 
-import org.hamcrest.core.IsEqual
-import org.hamcrest.core.IsNull
-import org.junit.Assert.assertThat
-import org.junit.Test
-import java.io.IOException
+import kotlin.test.*
 
 class WithTimeoutOrNullTest : TestBase() {
-    /**
-     * Tests a case of no timeout and no suspension inside.
-     */
-    @Test
-    fun testBasicNoSuspend() = runTest {
-        expect(1)
-        val result = withTimeoutOrNull(10_000) {
-            expect(2)
-            "OK"
-        }
-        assertThat(result, IsEqual("OK"))
-        finish(3)
-    }
-
-    /**
-     * Tests a case of no timeout and one suspension inside.
-     */
-    @Test
-    fun testBasicSuspend() = runTest {
-        expect(1)
-        val result = withTimeoutOrNull(10_000) {
-            expect(2)
-            yield()
-            expect(3)
-            "OK"
-        }
-        assertThat(result, IsEqual("OK"))
-        finish(4)
-    }
-
-    /**
-     * Tests property dispatching of `withTimeoutOrNull` blocks
-     */
-    @Test
-    fun testDispatch() = runTest {
-        expect(1)
-        launch(coroutineContext) {
-            expect(4)
-            yield() // back to main
-            expect(7)
-        }
-        expect(2)
-        // test that it does not yield to the above job when started
-        val result = withTimeoutOrNull(1000) {
-            expect(3)
-            yield() // yield only now
-            expect(5)
-            "OK"
-        }
-        assertThat(result, IsEqual("OK"))
-        expect(6)
-        yield() // back to launch
-        finish(8)
-    }
-
     @Test
     fun testNullOnTimeout() = runTest {
         expect(1)
@@ -87,7 +28,7 @@
             expectUnreached()
             "OK"
         }
-        assertThat(result, IsNull())
+        assertEquals(null, result)
         finish(3)
     }
 
@@ -103,13 +44,13 @@
             }
             "OK"
         }
-        assertThat(result, IsNull())
+        assertEquals(null, result)
         finish(4)
     }
 
     @Test
     fun testSuppressExceptionWithAnotherException() = runTest(
-        expected = { it is IOException }
+        expected = { it is TestException }
     ) {
         expect(1)
         val result = withTimeoutOrNull(100) {
@@ -118,7 +59,7 @@
                 delay(1000)
             } catch (e: CancellationException) {
                 finish(3)
-                throw IOException(e)
+                throw TestException()
             }
             expectUnreached()
             "OK"
@@ -126,56 +67,8 @@
         expectUnreached()
     }
 
-    /**
-     * Tests that a 100% CPU-consuming loop will react on timeout if it has yields.
-     */
     @Test
-    fun testYieldBlockingWithTimeout() = runBlocking {
-        expect(1)
-        val result = withTimeoutOrNull(100) {
-            while (true) {
-                yield()
-            }
-        }
-        assertThat(result, IsNull())
-        finish(2)
-    }
-
-    @Test(expected = CancellationException::class)
-    fun testInnerTimeoutTest() = runBlocking {
-        withTimeoutOrNull(200) {
-            withTimeout(100) {
-                while (true) {
-                    yield()
-                }
-            }
-            expectUnreached() // will timeout
-        }
-        expectUnreached() // will timeout
-    }
-
-    @Test
-    fun testOuterTimeoutTest() = runBlocking {
-        var counter = 0
-        val result = withTimeoutOrNull(250) {
-            while (true) {
-                val inner = withTimeoutOrNull(100) {
-                    while (true) {
-                        yield()
-                    }
-                }
-                assertThat(inner, IsNull())
-                counter++
-            }
-        }
-        assertThat(result, IsNull())
-        // under load counter may be equal to 1, so the check is lenient here
-        println("Executed: $counter times")
-        check(counter in 1..2)
-    }
-
-    @Test
-    fun testOuterTimeoutFiredBeforeInner() = runBlocking<Unit> {
+    fun testOuterTimeoutFiredBeforeInner() = runTest {
         val result = withTimeoutOrNull(100) {
             Thread.sleep(200) // wait enough for outer timeout to fire
             withContext(NonCancellable) { yield() } // give an event loop a chance to run and process that cancellation
@@ -186,6 +79,8 @@
             expectUnreached() // should not be reached, because it is outer timeout
         }
         // outer timeout results in null
-        assertThat(result, IsNull())
+        assertEquals(null, result)
     }
+
+    private class TestException : Exception()
 }
\ No newline at end of file
diff --git a/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/WithTimeoutOrNullThreadDispatchTest.kt b/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/WithTimeoutOrNullThreadDispatchTest.kt
index 6ffb153..df1387c 100644
--- a/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/WithTimeoutOrNullThreadDispatchTest.kt
+++ b/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/WithTimeoutOrNullThreadDispatchTest.kt
@@ -16,11 +16,7 @@
 
 package kotlinx.coroutines.experimental
 
-import org.hamcrest.core.IsEqual
-import org.hamcrest.core.IsNull
-import org.junit.After
-import org.junit.Assert
-import org.junit.Test
+import kotlin.test.*
 import java.util.concurrent.ExecutorService
 import java.util.concurrent.Executors
 import java.util.concurrent.ThreadFactory
@@ -30,7 +26,7 @@
 class WithTimeoutOrNullThreadDispatchTest : TestBase() {
     var executor: ExecutorService? = null
 
-    @After
+    @AfterTest
     fun tearDown() {
         executor?.shutdown()
     }
@@ -78,7 +74,7 @@
         val dispatcher = factory(ThreadFactory { Thread(it).also { thread = it } })
         withContext(dispatcher) {
             expect(2)
-            Assert.assertThat(Thread.currentThread(), IsEqual(thread))
+            assertEquals(thread, Thread.currentThread())
             val result = withTimeoutOrNull(100) {
                 try {
                     expect(3)
@@ -86,12 +82,12 @@
                     expectUnreached()
                 } catch (e: CancellationException) {
                     expect(4)
-                    Assert.assertThat(Thread.currentThread(), IsEqual(thread))
+                    assertEquals(thread, Thread.currentThread())
                     throw e // rethrow
                 }
             }
-            Assert.assertThat(Thread.currentThread(), IsEqual(thread))
-            Assert.assertThat(result, IsNull())
+            assertEquals(thread, Thread.currentThread())
+            assertEquals(null, result)
             expect(5)
         }
         finish(6)
diff --git a/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/WithTimeoutTest.kt b/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/WithTimeoutTest.kt
index aa51f23..a793a1e 100644
--- a/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/WithTimeoutTest.kt
+++ b/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/WithTimeoutTest.kt
@@ -14,70 +14,14 @@
  * limitations under the License.
  */
 
+@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913
+
 package kotlinx.coroutines.experimental
 
-import org.hamcrest.core.IsEqual
-import org.junit.Assert.assertThat
-import org.junit.Test
+import kotlin.test.*
 import java.io.IOException
 
 class WithTimeoutTest : TestBase() {
-    /**
-     * Tests a case of no timeout and no suspension inside.
-     */
-    @Test
-    fun testBasicNoSuspend() = runTest {
-        expect(1)
-        val result = withTimeout(10_000) {
-            expect(2)
-            "OK"
-        }
-        assertThat(result, IsEqual("OK"))
-        finish(3)
-    }
-
-    /**
-     * Tests a case of no timeout and one suspension inside.
-     */
-    @Test
-    fun testBasicSuspend() = runTest {
-        expect(1)
-        val result = withTimeout(10_000) {
-            expect(2)
-            yield()
-            expect(3)
-            "OK"
-        }
-        assertThat(result, IsEqual("OK"))
-        finish(4)
-    }
-
-    /**
-     * Tests proper dispatching of `withTimeout` blocks
-     */
-    @Test
-    fun testDispatch() = runTest {
-        expect(1)
-        launch(coroutineContext) {
-            expect(4)
-            yield() // back to main
-            expect(7)
-        }
-        expect(2)
-        // test that it does not yield to the above job when started
-        val result = withTimeout(1000) {
-            expect(3)
-            yield() // yield only now
-            expect(5)
-            "OK"
-        }
-        assertThat(result, IsEqual("OK"))
-        expect(6)
-        yield() // back to launch
-        finish(8)
-    }
-
-
     @Test
     fun testExceptionOnTimeout() = runTest {
         expect(1)
@@ -89,7 +33,7 @@
                 "OK"
             }
         } catch (e: CancellationException) {
-            assertThat(e.message, IsEqual("Timed out waiting for 100 MILLISECONDS"))
+            assertEquals("Timed out waiting for 100 MILLISECONDS", e.message)
             finish(3)
         }
     }
@@ -129,34 +73,4 @@
         }
         expectUnreached()
     }
-
-    /**
-     * Tests that a 100% CPU-consuming loop will react on timeout if it has yields.
-     */
-    @Test(expected = CancellationException::class)
-    fun testYieldBlockingWithTimeout() = runTest {
-        withTimeout(100) {
-            while (true) {
-                yield()
-            }
-        }
-    }
-
-    /**
-     * Tests that [withTimeout] waits for children coroutines to complete.
-     */
-    @Test
-    fun testWithTimeoutChildWait() = runTest {
-        expect(1)
-        withTimeout(100) {
-            expect(2)
-            // launch child with timeout
-            launch(coroutineContext) {
-                expect(4)
-            }
-            expect(3)
-            // now will wait for child before returning
-        }
-        finish(5)
-    }
 }
\ No newline at end of file
diff --git a/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/WithTimeoutThreadDispatchTest.kt b/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/WithTimeoutThreadDispatchTest.kt
index 806a30c..8529b8c 100644
--- a/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/WithTimeoutThreadDispatchTest.kt
+++ b/core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/WithTimeoutThreadDispatchTest.kt
@@ -16,10 +16,7 @@
 
 package kotlinx.coroutines.experimental
 
-import org.hamcrest.core.IsEqual
-import org.junit.After
-import org.junit.Assert
-import org.junit.Test
+import kotlin.test.*
 import java.util.concurrent.ExecutorService
 import java.util.concurrent.Executors
 import java.util.concurrent.ThreadFactory
@@ -29,7 +26,7 @@
 class WithTimeoutThreadDispatchTest : TestBase() {
     var executor: ExecutorService? = null
 
-    @After
+    @AfterTest
     fun tearDown() {
         executor?.shutdown()
     }
@@ -76,7 +73,7 @@
         val dispatcher = factory(ThreadFactory { Thread(it).also { thread = it } })
         withContext(dispatcher) {
             expect(2)
-            Assert.assertThat(Thread.currentThread(), IsEqual(thread))
+            assertEquals(thread, Thread.currentThread())
             try {
                 withTimeout(100) {
                     try {
@@ -85,13 +82,13 @@
                         expectUnreached()
                     } catch (e: CancellationException) {
                         expect(4)
-                        Assert.assertThat(Thread.currentThread(), IsEqual(thread))
+                        assertEquals(thread, Thread.currentThread())
                         throw e // rethrow
                     }
                 }
             } catch (e: CancellationException) {
                 expect(5)
-                Assert.assertThat(Thread.currentThread(), IsEqual(thread))
+                assertEquals(thread, Thread.currentThread())
             }
             expect(6)
         }