Skip to content

Commit 67661d9

Browse files
committed
Fixes
1 parent 2f818a3 commit 67661d9

File tree

5 files changed

+15
-18
lines changed

5 files changed

+15
-18
lines changed

kotlinx-coroutines-test/common/src/DelayController.kt

+2-9
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ public interface DelayController {
8484
/**
8585
* Call after test code completes to ensure that the dispatcher is properly cleaned up.
8686
*
87-
* @throws UncompletedCoroutinesError if any pending tasks are active, however it will not throw for suspended
87+
* @throws AssertionError if any pending tasks are active, however it will not throw for suspended
8888
* coroutines.
8989
*/
9090
@ExperimentalCoroutinesApi
91-
@Throws(UncompletedCoroutinesError::class)
91+
@Throws(AssertionError::class)
9292
public fun cleanupTestCoroutines()
9393

9494
/**
@@ -123,13 +123,6 @@ public interface DelayController {
123123
public fun resumeDispatcher()
124124
}
125125

126-
/**
127-
* Thrown when a test has completed and there are tasks that are not completed or cancelled.
128-
*/
129-
// todo: maybe convert into non-public class in 1.3.0 (need use-cases for a public exception type)
130-
@ExperimentalCoroutinesApi
131-
public class UncompletedCoroutinesError(message: String): AssertionError(message)
132-
133126
internal interface SchedulerAsDelayController: DelayController {
134127
public val scheduler: TestCoroutineScheduler
135128

kotlinx-coroutines-test/common/src/TestBuilders.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import kotlin.coroutines.*
3434
*
3535
* Unhandled exceptions thrown by coroutines in the test will be re-thrown at the end of the test.
3636
*
37-
* @throws UncompletedCoroutinesError If the [testBody] does not complete (or cancel) all coroutines that it launches
37+
* @throws AssertionError If the [testBody] does not complete (or cancel) all coroutines that it launches
3838
* (including coroutines suspended on join/await).
3939
*
4040
* @param context additional context elements. If [context] contains [CoroutineDispatcher] or [CoroutineExceptionHandler],

kotlinx-coroutines-test/common/src/TestCoroutineScheduler.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ import kotlin.jvm.*
2424
*/
2525
@ExperimentalCoroutinesApi
2626
// TODO: maybe make this a `TimeSource`?
27-
public class TestCoroutineScheduler: AbstractCoroutineContextElement(TestCoroutineScheduler), CoroutineContext.Element {
27+
public class TestCoroutineScheduler : AbstractCoroutineContextElement(TestCoroutineScheduler),
28+
CoroutineContext.Element {
2829

2930
/** @suppress */
30-
public companion object Key: CoroutineContext.Key<TestCoroutineScheduler>
31+
public companion object Key : CoroutineContext.Key<TestCoroutineScheduler>
3132

3233
/** This heap stores the knowledge about which dispatchers are interested in which moments of virtual time. */
3334
// TODO: all the synchronization is done via a separate lock, so a non-thread-safe priority queue can be used.
@@ -55,7 +56,7 @@ public class TestCoroutineScheduler: AbstractCoroutineContextElement(TestCorouti
5556
dispatcher: TestDispatcher,
5657
timeDeltaMillis: Long,
5758
marker: T,
58-
isCancelled : (T) -> Boolean
59+
isCancelled: (T) -> Boolean
5960
): DisposableHandle {
6061
require(timeDeltaMillis >= 0) { "Attempted scheduling an event earlier in time (with the time delta $timeDeltaMillis)" }
6162
val count = count.getAndIncrement()

kotlinx-coroutines-test/common/src/TestCoroutineScope.kt

+8-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import kotlin.coroutines.*
1111
* A scope which provides detailed control over the execution of coroutines for tests.
1212
*/
1313
@ExperimentalCoroutinesApi
14-
public interface TestCoroutineScope: CoroutineScope, UncaughtExceptionCaptor {
14+
public sealed interface TestCoroutineScope: CoroutineScope, UncaughtExceptionCaptor {
1515
/**
1616
* Call after the test completes.
1717
* Calls [UncaughtExceptionCaptor.cleanupTestCoroutinesCaptor] and [DelayController.cleanupTestCoroutines].
1818
*
1919
* @throws Throwable the first uncaught exception, if there are any uncaught exceptions.
20-
* @throws UncompletedCoroutinesError if any pending tasks are active, however it will not throw for suspended
20+
* @throws AssertionError if any pending tasks are active, however it will not throw for suspended
2121
* coroutines.
2222
*/
2323
@ExperimentalCoroutinesApi
@@ -28,8 +28,6 @@ public interface TestCoroutineScope: CoroutineScope, UncaughtExceptionCaptor {
2828
*/
2929
@ExperimentalCoroutinesApi
3030
public val testScheduler: TestCoroutineScheduler
31-
get() = coroutineContext[TestCoroutineScheduler]
32-
?: throw UnsupportedOperationException("This scope does not have a TestCoroutineScheduler linked to it")
3331
}
3432

3533
private class TestCoroutineScopeImpl (
@@ -158,3 +156,9 @@ public fun TestCoroutineScope.resumeDispatcher() {
158156
private val TestCoroutineScope.delayControllerForPausing: DelayController
159157
get() = coroutineContext.delayController
160158
?: throw IllegalStateException("This scope isn't able to pause its dispatchers")
159+
160+
/**
161+
* Thrown when a test has completed and there are tasks that are not completed or cancelled.
162+
*/
163+
@ExperimentalCoroutinesApi
164+
internal class UncompletedCoroutinesError(message: String): AssertionError(message)

kotlinx-coroutines-test/common/src/TestDispatcher.kt

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public abstract class TestDispatcher: CoroutineDispatcher(), Delay {
1818
public abstract val scheduler: TestCoroutineScheduler
1919

2020
/** Notifies the dispatcher that it should process a single event marked with [marker] happening at time [time]. */
21-
@ExperimentalCoroutinesApi
2221
internal abstract fun processEvent(time: Long, marker: Any)
2322

2423
/** @suppress */

0 commit comments

Comments
 (0)