Skip to content

Commit 5509e90

Browse files
committed
Fixes
1 parent 2f818a3 commit 5509e90

File tree

7 files changed

+17
-29
lines changed

7 files changed

+17
-29
lines changed

kotlinx-coroutines-test/README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ suspend fun bar() {}
114114
```
115115

116116
`runBlockingTest` will auto-progress virtual time until all coroutines are completed before returning. If any coroutines
117-
are not able to complete, an [UncompletedCoroutinesError] will be thrown.
117+
are not able to complete, an `AssertionError` will be thrown.
118118

119119
*Note:* The default eager behavior of [runBlockingTest] will ignore [CoroutineStart] parameters.
120120

@@ -148,7 +148,7 @@ suspend fun CoroutineScope.foo() {
148148
*Note:* `runBlockingTest` will always attempt to auto-progress time until all coroutines are completed just before
149149
exiting. This is a convenience to avoid having to call [advanceUntilIdle][DelayController.advanceUntilIdle]
150150
as the last line of many common test cases.
151-
If any coroutines cannot complete by advancing time, an [UncompletedCoroutinesError] is thrown.
151+
If any coroutines cannot complete by advancing time, an `AssertionError` is thrown.
152152

153153
### Testing `withTimeout` using `runBlockingTest`
154154

@@ -447,7 +447,6 @@ If you have any suggestions for improvements to this experimental API please sha
447447

448448
[setMain]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-test/kotlinx.coroutines.test/set-main.html
449449
[runBlockingTest]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-test/kotlinx.coroutines.test/run-blocking-test.html
450-
[UncompletedCoroutinesError]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-test/kotlinx.coroutines.test/-uncompleted-coroutines-error/index.html
451450
[DelayController]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/index.html
452451
[DelayController.advanceUntilIdle]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/advance-until-idle.html
453452
[DelayController.pauseDispatcher]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/pause-dispatcher.html

kotlinx-coroutines-test/api/kotlinx-coroutines-test.api

-8
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ public abstract interface class kotlinx/coroutines/test/TestCoroutineScope : kot
5858
public abstract fun getTestScheduler ()Lkotlinx/coroutines/test/TestCoroutineScheduler;
5959
}
6060

61-
public final class kotlinx/coroutines/test/TestCoroutineScope$DefaultImpls {
62-
public static fun getTestScheduler (Lkotlinx/coroutines/test/TestCoroutineScope;)Lkotlinx/coroutines/test/TestCoroutineScheduler;
63-
}
64-
6561
public final class kotlinx/coroutines/test/TestCoroutineScopeKt {
6662
public static final fun TestCoroutineScope (Lkotlin/coroutines/CoroutineContext;)Lkotlinx/coroutines/test/TestCoroutineScope;
6763
public static synthetic fun TestCoroutineScope$default (Lkotlin/coroutines/CoroutineContext;ILjava/lang/Object;)Lkotlinx/coroutines/test/TestCoroutineScope;
@@ -92,7 +88,3 @@ public abstract interface class kotlinx/coroutines/test/UncaughtExceptionCaptor
9288
public abstract fun getUncaughtExceptions ()Ljava/util/List;
9389
}
9490

95-
public final class kotlinx/coroutines/test/UncompletedCoroutinesError : java/lang/AssertionError {
96-
public fun <init> (Ljava/lang/String;)V
97-
}
98-

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)