Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dkhalanskyjb committed Nov 17, 2021
1 parent ae82754 commit 97d0f47
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion kotlinx-coroutines-test/common/src/TestBuilders.kt
Expand Up @@ -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]).
Expand Down
Expand Up @@ -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,
Expand All @@ -155,4 +156,4 @@ private class StandardTestDispatcherImpl(
}

override fun toString(): String = "${name ?: "StandardTestDispatcher"}[scheduler=$scheduler]"
}
}
Expand Up @@ -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<T>(private val initialValue: T, private val name: String) {
private class NonConcurrentlyModifiable<T>(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<Throwable?> = atomic(null) // exception from reading
Expand All @@ -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()
Expand All @@ -93,4 +93,4 @@ private val defaultDelay
inline get() = DefaultDelay

@Suppress("INVISIBLE_MEMBER")
internal expect fun Dispatchers.getTestMainDispatcher(): TestMainDispatcher
internal expect fun Dispatchers.getTestMainDispatcher(): TestMainDispatcher

0 comments on commit 97d0f47

Please sign in to comment.