Skip to content

Commit 8baa736

Browse files
committed
Migrate from deprecated API
1 parent bbd1335 commit 8baa736

17 files changed

+72
-72
lines changed

kotlinx-coroutines-core/common/test/AsyncLazyTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class AsyncLazyTest : TestBase() {
7676
expected = { it is TestException }
7777
) {
7878
expect(1)
79-
val d = async(start = CoroutineStart.LAZY) {
79+
val d = async<Unit>(start = CoroutineStart.LAZY) {
8080
finish(3)
8181
throw TestException()
8282
}
@@ -90,7 +90,7 @@ class AsyncLazyTest : TestBase() {
9090
expected = { it is TestException }
9191
) {
9292
expect(1)
93-
val d = async(start = CoroutineStart.LAZY) {
93+
val d = async<Unit>(start = CoroutineStart.LAZY) {
9494
expect(3)
9595
yield() // this has not effect, because parent coroutine is waiting
9696
finish(4)
@@ -104,7 +104,7 @@ class AsyncLazyTest : TestBase() {
104104
@Test
105105
fun testCatchException() = runTest {
106106
expect(1)
107-
val d = async(NonCancellable, start = CoroutineStart.LAZY) {
107+
val d = async<Unit>(NonCancellable, start = CoroutineStart.LAZY) {
108108
expect(3)
109109
throw TestException()
110110
}
@@ -184,4 +184,4 @@ class AsyncLazyTest : TestBase() {
184184
assertEquals(d.await(), 42) // await shall throw CancellationException
185185
expectUnreached()
186186
}
187-
}
187+
}

kotlinx-coroutines-core/common/test/AsyncTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class AsyncTest : TestBase() {
4343
@Test
4444
fun testSimpleException() = runTest(expected = { it is TestException }) {
4545
expect(1)
46-
val d = async {
46+
val d = async<Unit> {
4747
finish(3)
4848
throw TestException()
4949
}
@@ -170,7 +170,7 @@ class AsyncTest : TestBase() {
170170
@Test
171171
fun testDeferAndYieldException() = runTest(expected = { it is TestException }) {
172172
expect(1)
173-
val d = async {
173+
val d = async<Unit> {
174174
expect(3)
175175
yield() // no effect, parent waiting
176176
finish(4)

kotlinx-coroutines-core/common/test/AtomicCancellationCommonTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class AtomicCancellationCommonTest : TestBase() {
140140
val mutex = Mutex(true) // locked mutex
141141
val job = launch(start = CoroutineStart.UNDISPATCHED) {
142142
expect(2)
143-
val result = select<String> { // suspends
143+
select<String> { // suspends
144144
mutex.onLock {
145145
expect(4)
146146
"OK"

kotlinx-coroutines-core/common/test/CancellableResumeTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class CancellableResumeTest : TestBase() {
8282
cont.invokeOnCancellation { expect(3) }
8383
ctx.cancel()
8484
expect(4)
85-
cont.resume("OK") { cause ->
85+
cont.resume("OK") {
8686
expect(5)
8787
}
8888
finish(6)
@@ -108,7 +108,7 @@ class CancellableResumeTest : TestBase() {
108108
}
109109
ctx.cancel()
110110
expect(4)
111-
cont.resume("OK") { cause ->
111+
cont.resume("OK") {
112112
expect(5)
113113
throw TestException3("FAIL") // onCancellation block fails with exception
114114
}

kotlinx-coroutines-core/common/test/UndispatchedResultTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class UndispatchedResultTest : TestBase() {
5555
try {
5656
expect(1)
5757
// Will cancel its parent
58-
async(context) {
58+
async<Unit>(context) {
5959
expect(2)
6060
throw TestException()
6161
}.await()

kotlinx-coroutines-core/common/test/WithTimeoutDurationTest.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class WithTimeoutDurationTest : TestBase() {
1717
@Test
1818
fun testBasicNoSuspend() = runTest {
1919
expect(1)
20-
val result = withTimeout(10.seconds) {
20+
val result = withTimeout(Duration.seconds(10)) {
2121
expect(2)
2222
"OK"
2323
}
@@ -31,7 +31,7 @@ class WithTimeoutDurationTest : TestBase() {
3131
@Test
3232
fun testBasicSuspend() = runTest {
3333
expect(1)
34-
val result = withTimeout(10.seconds) {
34+
val result = withTimeout(Duration.seconds(10)) {
3535
expect(2)
3636
yield()
3737
expect(3)
@@ -54,7 +54,7 @@ class WithTimeoutDurationTest : TestBase() {
5454
}
5555
expect(2)
5656
// test that it does not yield to the above job when started
57-
val result = withTimeout(1.seconds) {
57+
val result = withTimeout(Duration.seconds(1)) {
5858
expect(3)
5959
yield() // yield only now
6060
expect(5)
@@ -74,7 +74,7 @@ class WithTimeoutDurationTest : TestBase() {
7474
fun testYieldBlockingWithTimeout() = runTest(
7575
expected = { it is CancellationException }
7676
) {
77-
withTimeout(100.milliseconds) {
77+
withTimeout(Duration.milliseconds(100)) {
7878
while (true) {
7979
yield()
8080
}
@@ -87,7 +87,7 @@ class WithTimeoutDurationTest : TestBase() {
8787
@Test
8888
fun testWithTimeoutChildWait() = runTest {
8989
expect(1)
90-
withTimeout(100.milliseconds) {
90+
withTimeout(Duration.milliseconds(100)) {
9191
expect(2)
9292
// launch child with timeout
9393
launch {
@@ -102,7 +102,7 @@ class WithTimeoutDurationTest : TestBase() {
102102
@Test
103103
fun testBadClass() = runTest {
104104
val bad = BadClass()
105-
val result = withTimeout(100.milliseconds) {
105+
val result = withTimeout(Duration.milliseconds(100)) {
106106
bad
107107
}
108108
assertSame(bad, result)
@@ -118,9 +118,9 @@ class WithTimeoutDurationTest : TestBase() {
118118
fun testExceptionOnTimeout() = runTest {
119119
expect(1)
120120
try {
121-
withTimeout(100.milliseconds) {
121+
withTimeout(Duration.milliseconds(100)) {
122122
expect(2)
123-
delay(1000.milliseconds)
123+
delay(Duration.milliseconds(1000))
124124
expectUnreached()
125125
"OK"
126126
}
@@ -135,10 +135,10 @@ class WithTimeoutDurationTest : TestBase() {
135135
expected = { it is CancellationException }
136136
) {
137137
expect(1)
138-
withTimeout(100.milliseconds) {
138+
withTimeout(Duration.milliseconds(100)) {
139139
expect(2)
140140
try {
141-
delay(1000.milliseconds)
141+
delay(Duration.milliseconds(1000))
142142
} catch (e: CancellationException) {
143143
finish(3)
144144
}
@@ -151,10 +151,10 @@ class WithTimeoutDurationTest : TestBase() {
151151
fun testSuppressExceptionWithAnotherException() = runTest {
152152
expect(1)
153153
try {
154-
withTimeout(100.milliseconds) {
154+
withTimeout(Duration.milliseconds(100)) {
155155
expect(2)
156156
try {
157-
delay(1000.milliseconds)
157+
delay(Duration.milliseconds(1000))
158158
} catch (e: CancellationException) {
159159
expect(3)
160160
throw TestException()
@@ -172,7 +172,7 @@ class WithTimeoutDurationTest : TestBase() {
172172
fun testNegativeTimeout() = runTest {
173173
expect(1)
174174
try {
175-
withTimeout(-1.milliseconds) {
175+
withTimeout(-Duration.milliseconds(1)) {
176176
expectUnreached()
177177
"OK"
178178
}
@@ -187,7 +187,7 @@ class WithTimeoutDurationTest : TestBase() {
187187
expect(1)
188188
try {
189189
expect(2)
190-
withTimeout(1.seconds) {
190+
withTimeout(Duration.seconds(1)) {
191191
expect(3)
192192
throw TestException()
193193
}

kotlinx-coroutines-core/common/test/WithTimeoutOrNullDurationTest.kt

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
1919
@Test
2020
fun testBasicNoSuspend() = runTest {
2121
expect(1)
22-
val result = withTimeoutOrNull(10.seconds) {
22+
val result = withTimeoutOrNull(Duration.seconds(10)) {
2323
expect(2)
2424
"OK"
2525
}
@@ -33,7 +33,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
3333
@Test
3434
fun testBasicSuspend() = runTest {
3535
expect(1)
36-
val result = withTimeoutOrNull(10.seconds) {
36+
val result = withTimeoutOrNull(Duration.seconds(10)) {
3737
expect(2)
3838
yield()
3939
expect(3)
@@ -56,7 +56,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
5656
}
5757
expect(2)
5858
// test that it does not yield to the above job when started
59-
val result = withTimeoutOrNull(1.seconds) {
59+
val result = withTimeoutOrNull(Duration.seconds(1)) {
6060
expect(3)
6161
yield() // yield only now
6262
expect(5)
@@ -74,7 +74,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
7474
@Test
7575
fun testYieldBlockingWithTimeout() = runTest {
7676
expect(1)
77-
val result = withTimeoutOrNull(100.milliseconds) {
77+
val result = withTimeoutOrNull(Duration.milliseconds(100)) {
7878
while (true) {
7979
yield()
8080
}
@@ -86,15 +86,15 @@ class WithTimeoutOrNullDurationTest : TestBase() {
8686
@Test
8787
fun testSmallTimeout() = runTest {
8888
val channel = Channel<Int>(1)
89-
val value = withTimeoutOrNull(1.milliseconds) {
89+
val value = withTimeoutOrNull(Duration.milliseconds(1)) {
9090
channel.receive()
9191
}
9292
assertNull(value)
9393
}
9494

9595
@Test
9696
fun testThrowException() = runTest(expected = {it is AssertionError}) {
97-
withTimeoutOrNull(Duration.INFINITE) {
97+
withTimeoutOrNull<Unit>(Duration.INFINITE) {
9898
throw AssertionError()
9999
}
100100
}
@@ -103,12 +103,13 @@ class WithTimeoutOrNullDurationTest : TestBase() {
103103
fun testInnerTimeout() = runTest(
104104
expected = { it is CancellationException }
105105
) {
106-
withTimeoutOrNull(1000.milliseconds) {
107-
withTimeout(10.milliseconds) {
106+
withTimeoutOrNull(Duration.milliseconds(1000)) {
107+
withTimeout(Duration.milliseconds(10)) {
108108
while (true) {
109109
yield()
110110
}
111111
}
112+
@Suppress("UNREACHABLE_CODE")
112113
expectUnreached() // will timeout
113114
}
114115
expectUnreached() // will timeout
@@ -118,7 +119,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
118119
fun testNestedTimeout() = runTest(expected = { it is TimeoutCancellationException }) {
119120
withTimeoutOrNull(Duration.INFINITE) {
120121
// Exception from this withTimeout is not suppressed by withTimeoutOrNull
121-
withTimeout(10.milliseconds) {
122+
withTimeout(Duration.milliseconds(10)) {
122123
delay(Duration.INFINITE)
123124
1
124125
}
@@ -130,9 +131,9 @@ class WithTimeoutOrNullDurationTest : TestBase() {
130131
@Test
131132
fun testOuterTimeout() = runTest {
132133
var counter = 0
133-
val result = withTimeoutOrNull(250.milliseconds) {
134+
val result = withTimeoutOrNull(Duration.milliseconds(250)) {
134135
while (true) {
135-
val inner = withTimeoutOrNull(100.milliseconds) {
136+
val inner = withTimeoutOrNull(Duration.milliseconds(100)) {
136137
while (true) {
137138
yield()
138139
}
@@ -148,7 +149,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
148149
@Test
149150
fun testBadClass() = runTest {
150151
val bad = BadClass()
151-
val result = withTimeoutOrNull(100.milliseconds) {
152+
val result = withTimeoutOrNull(Duration.milliseconds(100)) {
152153
bad
153154
}
154155
assertSame(bad, result)
@@ -163,9 +164,9 @@ class WithTimeoutOrNullDurationTest : TestBase() {
163164
@Test
164165
fun testNullOnTimeout() = runTest {
165166
expect(1)
166-
val result = withTimeoutOrNull(100.milliseconds) {
167+
val result = withTimeoutOrNull(Duration.milliseconds(100)) {
167168
expect(2)
168-
delay(1000.milliseconds)
169+
delay(Duration.milliseconds(1000))
169170
expectUnreached()
170171
"OK"
171172
}
@@ -176,10 +177,10 @@ class WithTimeoutOrNullDurationTest : TestBase() {
176177
@Test
177178
fun testSuppressExceptionWithResult() = runTest {
178179
expect(1)
179-
val result = withTimeoutOrNull(100.milliseconds) {
180+
val result = withTimeoutOrNull(Duration.milliseconds(100)) {
180181
expect(2)
181182
try {
182-
delay(1000.milliseconds)
183+
delay(Duration.milliseconds(1000))
183184
} catch (e: CancellationException) {
184185
expect(3)
185186
}
@@ -193,10 +194,10 @@ class WithTimeoutOrNullDurationTest : TestBase() {
193194
fun testSuppressExceptionWithAnotherException() = runTest {
194195
expect(1)
195196
try {
196-
withTimeoutOrNull(100.milliseconds) {
197+
withTimeoutOrNull(Duration.milliseconds(100)) {
197198
expect(2)
198199
try {
199-
delay(1000.milliseconds)
200+
delay(Duration.milliseconds(1000))
200201
} catch (e: CancellationException) {
201202
expect(3)
202203
throw TestException()
@@ -215,11 +216,11 @@ class WithTimeoutOrNullDurationTest : TestBase() {
215216
@Test
216217
fun testNegativeTimeout() = runTest {
217218
expect(1)
218-
var result = withTimeoutOrNull(-1.milliseconds) {
219+
var result = withTimeoutOrNull(-Duration.milliseconds(1)) {
219220
expectUnreached()
220221
}
221222
assertNull(result)
222-
result = withTimeoutOrNull(0.milliseconds) {
223+
result = withTimeoutOrNull(Duration.milliseconds(0)) {
223224
expectUnreached()
224225
}
225226
assertNull(result)
@@ -231,7 +232,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
231232
expect(1)
232233
try {
233234
expect(2)
234-
withTimeoutOrNull(1000.milliseconds) {
235+
withTimeoutOrNull<Unit>(Duration.milliseconds(1000)) {
235236
expect(3)
236237
throw TestException()
237238
}

kotlinx-coroutines-core/common/test/WithTimeoutOrNullTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class WithTimeoutOrNullTest : TestBase() {
9292

9393
@Test
9494
fun testThrowException() = runTest(expected = {it is AssertionError}) {
95-
withTimeoutOrNull(Long.MAX_VALUE) {
95+
withTimeoutOrNull<Unit>(Long.MAX_VALUE) {
9696
throw AssertionError()
9797
}
9898
}
@@ -107,6 +107,7 @@ class WithTimeoutOrNullTest : TestBase() {
107107
yield()
108108
}
109109
}
110+
@Suppress("UNREACHABLE_CODE")
110111
expectUnreached() // will timeout
111112
}
112113
expectUnreached() // will timeout

kotlinx-coroutines-core/common/test/flow/operators/CatchTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class CatchTest : TestBase() {
133133
.flowOn(d2)
134134
// flowOn with a different dispatcher introduces asynchrony so that all exceptions in the
135135
// upstream flows are handled before they go downstream
136-
.onEach { value ->
136+
.onEach {
137137
expectUnreached() // already cancelled
138138
}
139139
.catch { e ->

0 commit comments

Comments
 (0)