Skip to content

Commit 3feddff

Browse files
committed
Add API binary compatibility listing
- Removed some added-as-deprecated APIs that might have helped with automatic refactoring via ReplaceWith. Not sure if these should be shipped.
1 parent e64ac09 commit 3feddff

File tree

8 files changed

+100
-105
lines changed

8 files changed

+100
-105
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,79 @@
1+
public abstract interface class kotlinx/coroutines/test/DelayController {
2+
public abstract fun advanceTimeBy (JLjava/util/concurrent/TimeUnit;)J
3+
public abstract fun advanceTimeToNextDelayed ()J
4+
public abstract fun advanceUntilIdle ()J
5+
public abstract fun cleanupTestCoroutines ()V
6+
public abstract fun currentTime (Ljava/util/concurrent/TimeUnit;)J
7+
public abstract fun pauseDispatcher ()V
8+
public abstract fun pauseDispatcher (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
9+
public abstract fun resumeDispatcher ()V
10+
public abstract fun runCurrent ()V
11+
}
12+
13+
public final class kotlinx/coroutines/test/DelayController$DefaultImpls {
14+
public static synthetic fun advanceTimeBy$default (Lkotlinx/coroutines/test/DelayController;JLjava/util/concurrent/TimeUnit;ILjava/lang/Object;)J
15+
public static synthetic fun currentTime$default (Lkotlinx/coroutines/test/DelayController;Ljava/util/concurrent/TimeUnit;ILjava/lang/Object;)J
16+
}
17+
18+
public final class kotlinx/coroutines/test/TestBuilders {
19+
public static final fun runBlockingTest (Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;)V
20+
public static final fun runBlockingTest (Lkotlinx/coroutines/test/TestCoroutineDispatcher;Lkotlin/jvm/functions/Function2;)V
21+
public static final fun runBlockingTest (Lkotlinx/coroutines/test/TestCoroutineScope;Lkotlin/jvm/functions/Function2;)V
22+
public static synthetic fun runBlockingTest$default (Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
23+
public static final fun withTestContext (Lkotlinx/coroutines/test/TestCoroutineScope;Lkotlin/jvm/functions/Function2;)V
24+
}
25+
26+
public final class kotlinx/coroutines/test/TestCoroutineCoroutineExceptionHandler : kotlinx/coroutines/CoroutineExceptionHandler, kotlinx/coroutines/test/UncaughtExceptionCaptor {
27+
public fun <init> ()V
28+
public fun cleanupTestCoroutines ()V
29+
public fun fold (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object;
30+
public fun get (Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext$Element;
31+
public synthetic fun getKey ()Lkotlin/coroutines/CoroutineContext$Key;
32+
public fun getKey ()Lkotlinx/coroutines/CoroutineExceptionHandler$Key;
33+
public fun getUncaughtExceptions ()Ljava/util/List;
34+
public fun handleException (Lkotlin/coroutines/CoroutineContext;Ljava/lang/Throwable;)V
35+
public fun minusKey (Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext;
36+
public fun plus (Lkotlin/coroutines/CoroutineContext;)Lkotlin/coroutines/CoroutineContext;
37+
}
38+
39+
public final class kotlinx/coroutines/test/TestCoroutineDispatcher : kotlinx/coroutines/CoroutineDispatcher, kotlinx/coroutines/Delay, kotlinx/coroutines/test/DelayController {
40+
public fun <init> ()V
41+
public fun advanceTimeBy (JLjava/util/concurrent/TimeUnit;)J
42+
public fun advanceTimeToNextDelayed ()J
43+
public fun advanceUntilIdle ()J
44+
public fun cleanupTestCoroutines ()V
45+
public fun currentTime (Ljava/util/concurrent/TimeUnit;)J
46+
public fun delay (JLkotlin/coroutines/Continuation;)Ljava/lang/Object;
47+
public fun dispatch (Lkotlin/coroutines/CoroutineContext;Ljava/lang/Runnable;)V
48+
public fun invokeOnTimeout (JLjava/lang/Runnable;)Lkotlinx/coroutines/DisposableHandle;
49+
public fun pauseDispatcher ()V
50+
public fun pauseDispatcher (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
51+
public fun resumeDispatcher ()V
52+
public fun runCurrent ()V
53+
public fun scheduleResumeAfterDelay (JLkotlinx/coroutines/CancellableContinuation;)V
54+
public fun toString ()Ljava/lang/String;
55+
}
56+
57+
public abstract interface class kotlinx/coroutines/test/TestCoroutineScope : kotlinx/coroutines/CoroutineScope, kotlinx/coroutines/test/DelayController, kotlinx/coroutines/test/UncaughtExceptionCaptor {
58+
}
59+
60+
public final class kotlinx/coroutines/test/TestCoroutineScopeKt {
61+
public static final fun TestCoroutineScope (Lkotlin/coroutines/CoroutineContext;)Lkotlinx/coroutines/test/TestCoroutineScope;
62+
public static synthetic fun TestCoroutineScope$default (Lkotlin/coroutines/CoroutineContext;ILjava/lang/Object;)Lkotlinx/coroutines/test/TestCoroutineScope;
63+
}
64+
165
public final class kotlinx/coroutines/test/TestDispatchers {
266
public static final fun resetMain (Lkotlinx/coroutines/Dispatchers;)V
367
public static final fun setMain (Lkotlinx/coroutines/Dispatchers;Lkotlinx/coroutines/CoroutineDispatcher;)V
468
}
569

70+
public abstract interface class kotlinx/coroutines/test/UncaughtExceptionCaptor {
71+
public abstract fun cleanupTestCoroutines ()V
72+
public abstract fun getUncaughtExceptions ()Ljava/util/List;
73+
}
74+
75+
public final class kotlinx/coroutines/test/UncompletedCoroutinesError : java/lang/AssertionError {
76+
public fun <init> (Ljava/lang/String;Ljava/lang/Throwable;)V
77+
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/Throwable;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
78+
}
79+

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import kotlin.coroutines.CoroutineContext
3636
* @throws UncompletedCoroutinesError If the [testBody] does not complete (or cancel) all coroutines that it launches
3737
* (including coroutines suspended on join/await).
3838
*
39-
* @param context An optional context that MUST contain a [DelayController] and/or [TestCoroutineCoroutineExceptionHandler]
39+
* @param context An optional context that MUST contain a [DelayController] and/or [TestCoroutineExceptionHandler]
4040
* @param testBody The code of the unit-test.
4141
*/
4242
@ExperimentalCoroutinesApi
@@ -83,7 +83,7 @@ fun TestCoroutineDispatcher.runBlockingTest(block: suspend TestCoroutineScope.()
8383
}
8484

8585
private fun CoroutineContext?.checkArguments(): Pair<CoroutineContext, ContinuationInterceptor> {
86-
var safeContext= this ?: TestCoroutineCoroutineExceptionHandler() + TestCoroutineDispatcher()
86+
var safeContext= this ?: TestCoroutineExceptionHandler() + TestCoroutineDispatcher()
8787

8888
val dispatcher = safeContext[ContinuationInterceptor].run {
8989
this?.let {
@@ -96,7 +96,7 @@ private fun CoroutineContext?.checkArguments(): Pair<CoroutineContext, Continuat
9696
this?.let {
9797
require(this is UncaughtExceptionCaptor) { "coroutineExceptionHandler must implement UncaughtExceptionCaptor" }
9898
}
99-
this ?: TestCoroutineCoroutineExceptionHandler()
99+
this ?: TestCoroutineExceptionHandler()
100100
}
101101

102102
val job = safeContext[Job] ?: SupervisorJob()
@@ -108,7 +108,7 @@ private fun CoroutineContext?.checkArguments(): Pair<CoroutineContext, Continuat
108108
/**
109109
* This method is deprecated.
110110
*
111-
* @see [cleanupTestCoroutines]
111+
* @see [runBlocking]
112112
*/
113113
@Deprecated("This API has been deprecated to integrate with Structured Concurrency.",
114114
ReplaceWith("scope.runBlockingTest(testBody)", "kotlinx.coroutines.test"),

core/kotlinx-coroutines-test/src/TestCoroutineDispatcher.kt

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,6 @@ interface DelayController {
9999
*/
100100
@ExperimentalCoroutinesApi
101101
fun resumeDispatcher()
102-
103-
@Deprecated("This API has been deprecated to integrate with Structured Concurrency.",
104-
ReplaceWith("if (targetTime > currentTime(unit)) { advanceTimeBy(targetTime - currentTime(unit), unit) }",
105-
"kotlinx.coroutines.test"),
106-
level = DeprecationLevel.WARNING)
107-
fun advanceTimeTo(targetTime: Long, unit: TimeUnit = TimeUnit.MILLISECONDS) {
108-
advanceTimeBy(targetTime - currentTime(unit), unit)
109-
}
110-
111-
@Deprecated("This API has been deprecated to integrate with Structured Concurrency.",
112-
ReplaceWith("currentTime(unit)", "kotlinx.coroutines.test"),
113-
level = DeprecationLevel.WARNING)
114-
fun now(unit: TimeUnit = TimeUnit.MILLISECONDS) = currentTime(unit)
115-
116-
@Deprecated("This API has been deprecated to integrate with Structured Concurrency.",
117-
ReplaceWith("runCurrent()", "kotlinx.coroutines.test"),
118-
level = DeprecationLevel.WARNING)
119-
fun triggerActions() = runCurrent()
120102
}
121103

122104
/**
@@ -195,7 +177,7 @@ class TestCoroutineDispatcher:
195177
}
196178

197179

198-
private fun triggerActions(targetTime: Long) {
180+
private fun doActionsUntil(targetTime: Long) {
199181
while (true) {
200182
val current = queue.removeFirstIf { it.time <= targetTime } ?: break
201183
// If the scheduled time is 0 (immediate) use current virtual time
@@ -221,7 +203,7 @@ class TestCoroutineDispatcher:
221203
*/
222204
private fun advanceUntilTime(targetTime: Long, unit: TimeUnit) {
223205
val nanoTime = unit.toNanos(targetTime)
224-
triggerActions(nanoTime)
206+
doActionsUntil(nanoTime)
225207
if (nanoTime > time) time = nanoTime
226208
}
227209

@@ -241,7 +223,7 @@ class TestCoroutineDispatcher:
241223
return time - oldTime
242224
}
243225

244-
override fun runCurrent() = triggerActions(time)
226+
override fun runCurrent() = doActionsUntil(time)
245227

246228
override suspend fun pauseDispatcher(block: suspend () -> Unit) {
247229
val previous = dispatchImmediately
@@ -263,7 +245,7 @@ class TestCoroutineDispatcher:
263245

264246
override fun cleanupTestCoroutines() {
265247
// process any pending cancellations or completions, but don't advance time
266-
triggerActions(time)
248+
doActionsUntil(time)
267249

268250
// run through all pending tasks, ignore any submitted coroutines that are not active
269251
val pendingTasks = mutableListOf<TimedRunnable>()

core/kotlinx-coroutines-test/src/TestCoroutineCoroutineExceptionHandler.kt renamed to core/kotlinx-coroutines-test/src/TestCoroutineExceptionHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ interface UncaughtExceptionCaptor {
3030
* An exception handler that can be used to capture uncaught exceptions in tests.
3131
*/
3232
@ExperimentalCoroutinesApi
33-
class TestCoroutineCoroutineExceptionHandler: UncaughtExceptionCaptor, CoroutineExceptionHandler {
33+
class TestCoroutineExceptionHandler: UncaughtExceptionCaptor, CoroutineExceptionHandler {
3434

3535
override fun handleException(context: CoroutineContext, exception: Throwable) {
3636
synchronized(_exceptions) {

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
/*
23
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
34
*/
@@ -13,20 +14,10 @@ import kotlin.coroutines.CoroutineContext
1314
* A scope which provides detailed control over the execution of coroutines for tests.
1415
*/
1516
@ExperimentalCoroutinesApi
16-
interface TestCoroutineScope: CoroutineScope, UncaughtExceptionCaptor, DelayController {
17-
/**
18-
* This method is deprecated.
19-
*
20-
* @see [cleanupTestCoroutines]
21-
*/
22-
@Deprecated("This API has been deprecated to integrate with Structured Concurrency.",
23-
ReplaceWith("cleanupTestCoroutines()"),
24-
level = DeprecationLevel.WARNING)
25-
fun cancelAllActions() = cleanupTestCoroutines()
26-
}
17+
interface TestCoroutineScope: CoroutineScope, UncaughtExceptionCaptor, DelayController
2718

2819
private class TestCoroutineScopeImpl (
29-
context: CoroutineContext = TestCoroutineDispatcher() + TestCoroutineCoroutineExceptionHandler()):
20+
context: CoroutineContext = TestCoroutineDispatcher() + TestCoroutineExceptionHandler()):
3021
TestCoroutineScope,
3122
UncaughtExceptionCaptor by context.uncaughtExceptionDelegate,
3223
DelayController by context.delayDelegate
@@ -55,7 +46,7 @@ fun TestCoroutineScope(context: CoroutineContext? = null): TestCoroutineScope {
5546
safeContext += TestCoroutineDispatcher()
5647
}
5748
if (context[CoroutineExceptionHandler] == null) {
58-
safeContext += TestCoroutineCoroutineExceptionHandler()
49+
safeContext += TestCoroutineExceptionHandler()
5950
}
6051

6152
return TestCoroutineScopeImpl(safeContext)
@@ -66,7 +57,7 @@ private inline val CoroutineContext.uncaughtExceptionDelegate: UncaughtException
6657
val handler = this[CoroutineExceptionHandler]
6758
return handler as? UncaughtExceptionCaptor ?: throw
6859
IllegalArgumentException("TestCoroutineScope requires a UncaughtExceptionCaptor such as " +
69-
"TestCoroutineCoroutineExceptionHandler as the CoroutineExceptionHandler")
60+
"TestCoroutineExceptionHandler as the CoroutineExceptionHandler")
7061
}
7162

7263
private inline val CoroutineContext.delayDelegate: DelayController

core/kotlinx-coroutines-test/test/TestCoroutineDispatcherTest.kt

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -113,51 +113,4 @@ class TestCoroutineDispatcherTest {
113113
}
114114
subject.cleanupTestCoroutines()
115115
}
116-
117-
@Test
118-
fun whenCallingAdvanceTimeTo_itAdvancesToTheFuture() {
119-
val subject = TestCoroutineDispatcher()
120-
subject.advanceTimeTo(1_000)
121-
subject.advanceTimeTo(500)
122-
123-
assertEquals(1_000, subject.currentTime())
124-
}
125-
126-
@Test
127-
fun whenCallingAdvanceTimeTo_itOnlyAdvancesByDelta() {
128-
val subject = TestCoroutineDispatcher()
129-
subject.advanceTimeTo(1000)
130-
subject.advanceTimeTo(2000)
131-
132-
assertEquals(2_000, subject.currentTime())
133-
}
134-
135-
@Test
136-
fun whenNowCalled_returnsCurrentTime() {
137-
val subject = TestCoroutineDispatcher()
138-
subject.advanceTimeBy(1000)
139-
140-
assertEquals(1_000, subject.now())
141-
}
142-
143-
@Test
144-
fun whenCallingTriggerActions_currentActionsRun() {
145-
val subject = TestCoroutineDispatcher()
146-
subject.pauseDispatcher()
147-
val scope = CoroutineScope(subject)
148-
var executed = 0
149-
150-
scope.launch {
151-
executed++
152-
delay(1000)
153-
executed++
154-
}
155-
156-
assertEquals(0, executed)
157-
subject.triggerActions()
158-
assertEquals(1, executed)
159-
subject.advanceUntilIdle()
160-
assertEquals(2, executed)
161-
}
162-
163116
}

core/kotlinx-coroutines-test/test/TestCoroutineExceptionHandlerTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import kotlinx.coroutines.test.TestCoroutineCoroutineExceptionHandler
1+
import kotlinx.coroutines.test.TestCoroutineExceptionHandler
22
import org.junit.Test
33
import kotlin.test.assertEquals
44

55
class TestCoroutineExceptionHandlerTest {
66
@Test
77
fun whenExceptionsCaught_avaliableViaProperty() {
8-
val subject = TestCoroutineCoroutineExceptionHandler()
8+
val subject = TestCoroutineExceptionHandler()
99
val expected = IllegalArgumentException()
1010
subject.handleException(subject, expected)
1111
assertEquals(listOf(expected), subject.uncaughtExceptions)
Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
import kotlinx.coroutines.CoroutineExceptionHandler
22
import kotlinx.coroutines.newSingleThreadContext
3-
import kotlinx.coroutines.test.TestCoroutineDispatcher
4-
import kotlinx.coroutines.test.TestCoroutineCoroutineExceptionHandler
53
import kotlinx.coroutines.test.TestCoroutineScope
64
import org.junit.Test
5+
import kotlin.test.assertFails
76

87
class TestCoroutineScopeTest {
9-
@Test(expected = IllegalArgumentException::class)
8+
@Test
109
fun whenGivenInvalidExceptionHandler_throwsException() {
1110
val handler = CoroutineExceptionHandler { _, _ -> Unit }
12-
val subject = TestCoroutineScope(handler)
11+
assertFails {
12+
TestCoroutineScope(handler)
13+
}
1314
}
1415

15-
@Test(expected = IllegalArgumentException::class)
16+
@Test
1617
fun whenGivenInvalidDispatcher_throwsException() {
17-
val subject = TestCoroutineScope(newSingleThreadContext("incorrect call"))
18+
assertFails {
19+
TestCoroutineScope(newSingleThreadContext("incorrect call"))
20+
}
1821
}
19-
20-
@Test(expected = IllegalArgumentException::class)
21-
fun whenCancelAllActions_callsCleanupTestCoroutines() {
22-
val handler = TestCoroutineCoroutineExceptionHandler()
23-
val subject = TestCoroutineScope(handler + TestCoroutineDispatcher())
24-
handler.handleException(handler, IllegalArgumentException())
25-
subject.cancelAllActions()
26-
}
27-
}
22+
}

0 commit comments

Comments
 (0)