Skip to content

Commit

Permalink
Comments for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dkhalanskyjb committed Oct 14, 2021
1 parent c1a1ce5 commit 42a345e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
package kotlinx.coroutines.test

import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import kotlin.coroutines.*
import kotlin.test.*
import kotlin.time.*

class TestRunTest {
class RunTestTest {

/** Tests that [withContext] that sends work to other threads works in [runTest]. */
@Test
fun testWithContextDispatching() = runTest {
var counter = 0
Expand All @@ -20,6 +22,7 @@ class TestRunTest {
assertEquals(counter, 1)
}

/** Tests that joining [GlobalScope.launch] works in [runTest]. */
@Test
fun testJoiningForkedJob() = runTest {
var counter = 0
Expand All @@ -30,14 +33,16 @@ class TestRunTest {
assertEquals(counter, 1)
}

/** Tests [suspendCoroutine] not failing [runTest]. */
@Test
fun testSuspendCancellableCoroutine() = runTest {
fun testSuspendCoroutine() = runTest {
val answer = suspendCoroutine<Int> {
it.resume(42)
}
assertEquals(42, answer)
}

/** Tests that [runTest] attempts to detect it being run inside another [runTest] and failing in such scenarios. */
@Test
fun testNestedRunTestForbidden() = runTest {
assertFailsWith<IllegalStateException> {
Expand Down
1 change: 1 addition & 0 deletions kotlinx-coroutines-test/jvm/test/MultithreadingTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class MultithreadingTest {
}
}

/** Tests that resuming the coroutine of [runTest] asynchronously in reasonable time succeeds. */
@Test
fun testResumingFromAnotherThread() = runTest {
suspendCancellableCoroutine<Unit> { cont ->
Expand Down

0 comments on commit 42a345e

Please sign in to comment.