From 97d0f47f78518aa04ae70f10a64928a9c6eac193 Mon Sep 17 00:00:00 2001 From: Dmitry Khalanskiy Date: Wed, 17 Nov 2021 19:02:39 +0300 Subject: [PATCH] Fixes --- kotlinx-coroutines-test/common/src/TestBuilders.kt | 2 +- .../common/src/TestCoroutineDispatchers.kt | 3 ++- .../common/src/internal/TestMainDispatcher.kt | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/kotlinx-coroutines-test/common/src/TestBuilders.kt b/kotlinx-coroutines-test/common/src/TestBuilders.kt index bc591a35a3..e6d0c3970d 100644 --- a/kotlinx-coroutines-test/common/src/TestBuilders.kt +++ b/kotlinx-coroutines-test/common/src/TestBuilders.kt @@ -55,7 +55,7 @@ public expect class TestResult * immediately return the produced [TestResult] from the test method, without doing anything else afterwards. See * [TestResult] for details on this. * - * The test is run in a single thread, unless other [ContinuationInterceptor] are used for child coroutines. + * The test is run in a single thread, unless other [CoroutineDispatcher] are used for child coroutines. * Because of this, child coroutines are not executed in parallel to the test body. * In order to for the spawned-off asynchronous code to actually be executed, one must either [yield] or suspend the * test body some other way, or use commands that control scheduling (see [TestCoroutineScheduler]). diff --git a/kotlinx-coroutines-test/common/src/TestCoroutineDispatchers.kt b/kotlinx-coroutines-test/common/src/TestCoroutineDispatchers.kt index 184c673b34..4cc48f47d0 100644 --- a/kotlinx-coroutines-test/common/src/TestCoroutineDispatchers.kt +++ b/kotlinx-coroutines-test/common/src/TestCoroutineDispatchers.kt @@ -137,6 +137,7 @@ private class UnconfinedTestDispatcherImpl( * * @see UnconfinedTestDispatcher for a dispatcher that is not confined to any particular thread. */ +@ExperimentalCoroutinesApi @Suppress("FunctionName") public fun StandardTestDispatcher( scheduler: TestCoroutineScheduler? = null, @@ -155,4 +156,4 @@ private class StandardTestDispatcherImpl( } override fun toString(): String = "${name ?: "StandardTestDispatcher"}[scheduler=$scheduler]" -} \ No newline at end of file +} diff --git a/kotlinx-coroutines-test/common/src/internal/TestMainDispatcher.kt b/kotlinx-coroutines-test/common/src/internal/TestMainDispatcher.kt index 421af53aed..24e093be21 100644 --- a/kotlinx-coroutines-test/common/src/internal/TestMainDispatcher.kt +++ b/kotlinx-coroutines-test/common/src/internal/TestMainDispatcher.kt @@ -60,7 +60,7 @@ internal class TestMainDispatcher(delegate: CoroutineDispatcher): * The read operations never throw. Instead, the failures detected inside them will be remembered and thrown on the * next modification. */ - private class NonConcurrentlyModifiable(private val initialValue: T, private val name: String) { + private class NonConcurrentlyModifiable(initialValue: T, private val name: String) { private val readers = atomic(0) // number of concurrent readers private val isWriting = atomic(false) // a modification is happening currently private val exceptionWhenReading: AtomicRef = atomic(null) // exception from reading @@ -77,7 +77,7 @@ internal class TestMainDispatcher(delegate: CoroutineDispatcher): readers.decrementAndGet() return result } - set(value: T) { + set(value) { exceptionWhenReading.getAndSet(null)?.let { throw it } if (readers.value != 0) throw concurrentRW() if (!isWriting.compareAndSet(expect = false, update = true)) throw concurrentWW() @@ -93,4 +93,4 @@ private val defaultDelay inline get() = DefaultDelay @Suppress("INVISIBLE_MEMBER") -internal expect fun Dispatchers.getTestMainDispatcher(): TestMainDispatcher \ No newline at end of file +internal expect fun Dispatchers.getTestMainDispatcher(): TestMainDispatcher