Skip to content

Commit

Permalink
Migrate from deprecated API
Browse files Browse the repository at this point in the history
  • Loading branch information
qwwdfsad committed Aug 2, 2021
1 parent bbd1335 commit 8baa736
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 72 deletions.
8 changes: 4 additions & 4 deletions kotlinx-coroutines-core/common/test/AsyncLazyTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class AsyncLazyTest : TestBase() {
expected = { it is TestException }
) {
expect(1)
val d = async(start = CoroutineStart.LAZY) {
val d = async<Unit>(start = CoroutineStart.LAZY) {
finish(3)
throw TestException()
}
Expand All @@ -90,7 +90,7 @@ class AsyncLazyTest : TestBase() {
expected = { it is TestException }
) {
expect(1)
val d = async(start = CoroutineStart.LAZY) {
val d = async<Unit>(start = CoroutineStart.LAZY) {
expect(3)
yield() // this has not effect, because parent coroutine is waiting
finish(4)
Expand All @@ -104,7 +104,7 @@ class AsyncLazyTest : TestBase() {
@Test
fun testCatchException() = runTest {
expect(1)
val d = async(NonCancellable, start = CoroutineStart.LAZY) {
val d = async<Unit>(NonCancellable, start = CoroutineStart.LAZY) {
expect(3)
throw TestException()
}
Expand Down Expand Up @@ -184,4 +184,4 @@ class AsyncLazyTest : TestBase() {
assertEquals(d.await(), 42) // await shall throw CancellationException
expectUnreached()
}
}
}
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/common/test/AsyncTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AsyncTest : TestBase() {
@Test
fun testSimpleException() = runTest(expected = { it is TestException }) {
expect(1)
val d = async {
val d = async<Unit> {
finish(3)
throw TestException()
}
Expand Down Expand Up @@ -170,7 +170,7 @@ class AsyncTest : TestBase() {
@Test
fun testDeferAndYieldException() = runTest(expected = { it is TestException }) {
expect(1)
val d = async {
val d = async<Unit> {
expect(3)
yield() // no effect, parent waiting
finish(4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class AtomicCancellationCommonTest : TestBase() {
val mutex = Mutex(true) // locked mutex
val job = launch(start = CoroutineStart.UNDISPATCHED) {
expect(2)
val result = select<String> { // suspends
select<String> { // suspends
mutex.onLock {
expect(4)
"OK"
Expand Down
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/common/test/CancellableResumeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class CancellableResumeTest : TestBase() {
cont.invokeOnCancellation { expect(3) }
ctx.cancel()
expect(4)
cont.resume("OK") { cause ->
cont.resume("OK") {
expect(5)
}
finish(6)
Expand All @@ -108,7 +108,7 @@ class CancellableResumeTest : TestBase() {
}
ctx.cancel()
expect(4)
cont.resume("OK") { cause ->
cont.resume("OK") {
expect(5)
throw TestException3("FAIL") // onCancellation block fails with exception
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class UndispatchedResultTest : TestBase() {
try {
expect(1)
// Will cancel its parent
async(context) {
async<Unit>(context) {
expect(2)
throw TestException()
}.await()
Expand Down
28 changes: 14 additions & 14 deletions kotlinx-coroutines-core/common/test/WithTimeoutDurationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class WithTimeoutDurationTest : TestBase() {
@Test
fun testBasicNoSuspend() = runTest {
expect(1)
val result = withTimeout(10.seconds) {
val result = withTimeout(Duration.seconds(10)) {
expect(2)
"OK"
}
Expand All @@ -31,7 +31,7 @@ class WithTimeoutDurationTest : TestBase() {
@Test
fun testBasicSuspend() = runTest {
expect(1)
val result = withTimeout(10.seconds) {
val result = withTimeout(Duration.seconds(10)) {
expect(2)
yield()
expect(3)
Expand All @@ -54,7 +54,7 @@ class WithTimeoutDurationTest : TestBase() {
}
expect(2)
// test that it does not yield to the above job when started
val result = withTimeout(1.seconds) {
val result = withTimeout(Duration.seconds(1)) {
expect(3)
yield() // yield only now
expect(5)
Expand All @@ -74,7 +74,7 @@ class WithTimeoutDurationTest : TestBase() {
fun testYieldBlockingWithTimeout() = runTest(
expected = { it is CancellationException }
) {
withTimeout(100.milliseconds) {
withTimeout(Duration.milliseconds(100)) {
while (true) {
yield()
}
Expand All @@ -87,7 +87,7 @@ class WithTimeoutDurationTest : TestBase() {
@Test
fun testWithTimeoutChildWait() = runTest {
expect(1)
withTimeout(100.milliseconds) {
withTimeout(Duration.milliseconds(100)) {
expect(2)
// launch child with timeout
launch {
Expand All @@ -102,7 +102,7 @@ class WithTimeoutDurationTest : TestBase() {
@Test
fun testBadClass() = runTest {
val bad = BadClass()
val result = withTimeout(100.milliseconds) {
val result = withTimeout(Duration.milliseconds(100)) {
bad
}
assertSame(bad, result)
Expand All @@ -118,9 +118,9 @@ class WithTimeoutDurationTest : TestBase() {
fun testExceptionOnTimeout() = runTest {
expect(1)
try {
withTimeout(100.milliseconds) {
withTimeout(Duration.milliseconds(100)) {
expect(2)
delay(1000.milliseconds)
delay(Duration.milliseconds(1000))
expectUnreached()
"OK"
}
Expand All @@ -135,10 +135,10 @@ class WithTimeoutDurationTest : TestBase() {
expected = { it is CancellationException }
) {
expect(1)
withTimeout(100.milliseconds) {
withTimeout(Duration.milliseconds(100)) {
expect(2)
try {
delay(1000.milliseconds)
delay(Duration.milliseconds(1000))
} catch (e: CancellationException) {
finish(3)
}
Expand All @@ -151,10 +151,10 @@ class WithTimeoutDurationTest : TestBase() {
fun testSuppressExceptionWithAnotherException() = runTest {
expect(1)
try {
withTimeout(100.milliseconds) {
withTimeout(Duration.milliseconds(100)) {
expect(2)
try {
delay(1000.milliseconds)
delay(Duration.milliseconds(1000))
} catch (e: CancellationException) {
expect(3)
throw TestException()
Expand All @@ -172,7 +172,7 @@ class WithTimeoutDurationTest : TestBase() {
fun testNegativeTimeout() = runTest {
expect(1)
try {
withTimeout(-1.milliseconds) {
withTimeout(-Duration.milliseconds(1)) {
expectUnreached()
"OK"
}
Expand All @@ -187,7 +187,7 @@ class WithTimeoutDurationTest : TestBase() {
expect(1)
try {
expect(2)
withTimeout(1.seconds) {
withTimeout(Duration.seconds(1)) {
expect(3)
throw TestException()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
@Test
fun testBasicNoSuspend() = runTest {
expect(1)
val result = withTimeoutOrNull(10.seconds) {
val result = withTimeoutOrNull(Duration.seconds(10)) {
expect(2)
"OK"
}
Expand All @@ -33,7 +33,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
@Test
fun testBasicSuspend() = runTest {
expect(1)
val result = withTimeoutOrNull(10.seconds) {
val result = withTimeoutOrNull(Duration.seconds(10)) {
expect(2)
yield()
expect(3)
Expand All @@ -56,7 +56,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
}
expect(2)
// test that it does not yield to the above job when started
val result = withTimeoutOrNull(1.seconds) {
val result = withTimeoutOrNull(Duration.seconds(1)) {
expect(3)
yield() // yield only now
expect(5)
Expand All @@ -74,7 +74,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
@Test
fun testYieldBlockingWithTimeout() = runTest {
expect(1)
val result = withTimeoutOrNull(100.milliseconds) {
val result = withTimeoutOrNull(Duration.milliseconds(100)) {
while (true) {
yield()
}
Expand All @@ -86,15 +86,15 @@ class WithTimeoutOrNullDurationTest : TestBase() {
@Test
fun testSmallTimeout() = runTest {
val channel = Channel<Int>(1)
val value = withTimeoutOrNull(1.milliseconds) {
val value = withTimeoutOrNull(Duration.milliseconds(1)) {
channel.receive()
}
assertNull(value)
}

@Test
fun testThrowException() = runTest(expected = {it is AssertionError}) {
withTimeoutOrNull(Duration.INFINITE) {
withTimeoutOrNull<Unit>(Duration.INFINITE) {
throw AssertionError()
}
}
Expand All @@ -103,12 +103,13 @@ class WithTimeoutOrNullDurationTest : TestBase() {
fun testInnerTimeout() = runTest(
expected = { it is CancellationException }
) {
withTimeoutOrNull(1000.milliseconds) {
withTimeout(10.milliseconds) {
withTimeoutOrNull(Duration.milliseconds(1000)) {
withTimeout(Duration.milliseconds(10)) {
while (true) {
yield()
}
}
@Suppress("UNREACHABLE_CODE")
expectUnreached() // will timeout
}
expectUnreached() // will timeout
Expand All @@ -118,7 +119,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
fun testNestedTimeout() = runTest(expected = { it is TimeoutCancellationException }) {
withTimeoutOrNull(Duration.INFINITE) {
// Exception from this withTimeout is not suppressed by withTimeoutOrNull
withTimeout(10.milliseconds) {
withTimeout(Duration.milliseconds(10)) {
delay(Duration.INFINITE)
1
}
Expand All @@ -130,9 +131,9 @@ class WithTimeoutOrNullDurationTest : TestBase() {
@Test
fun testOuterTimeout() = runTest {
var counter = 0
val result = withTimeoutOrNull(250.milliseconds) {
val result = withTimeoutOrNull(Duration.milliseconds(250)) {
while (true) {
val inner = withTimeoutOrNull(100.milliseconds) {
val inner = withTimeoutOrNull(Duration.milliseconds(100)) {
while (true) {
yield()
}
Expand All @@ -148,7 +149,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
@Test
fun testBadClass() = runTest {
val bad = BadClass()
val result = withTimeoutOrNull(100.milliseconds) {
val result = withTimeoutOrNull(Duration.milliseconds(100)) {
bad
}
assertSame(bad, result)
Expand All @@ -163,9 +164,9 @@ class WithTimeoutOrNullDurationTest : TestBase() {
@Test
fun testNullOnTimeout() = runTest {
expect(1)
val result = withTimeoutOrNull(100.milliseconds) {
val result = withTimeoutOrNull(Duration.milliseconds(100)) {
expect(2)
delay(1000.milliseconds)
delay(Duration.milliseconds(1000))
expectUnreached()
"OK"
}
Expand All @@ -176,10 +177,10 @@ class WithTimeoutOrNullDurationTest : TestBase() {
@Test
fun testSuppressExceptionWithResult() = runTest {
expect(1)
val result = withTimeoutOrNull(100.milliseconds) {
val result = withTimeoutOrNull(Duration.milliseconds(100)) {
expect(2)
try {
delay(1000.milliseconds)
delay(Duration.milliseconds(1000))
} catch (e: CancellationException) {
expect(3)
}
Expand All @@ -193,10 +194,10 @@ class WithTimeoutOrNullDurationTest : TestBase() {
fun testSuppressExceptionWithAnotherException() = runTest {
expect(1)
try {
withTimeoutOrNull(100.milliseconds) {
withTimeoutOrNull(Duration.milliseconds(100)) {
expect(2)
try {
delay(1000.milliseconds)
delay(Duration.milliseconds(1000))
} catch (e: CancellationException) {
expect(3)
throw TestException()
Expand All @@ -215,11 +216,11 @@ class WithTimeoutOrNullDurationTest : TestBase() {
@Test
fun testNegativeTimeout() = runTest {
expect(1)
var result = withTimeoutOrNull(-1.milliseconds) {
var result = withTimeoutOrNull(-Duration.milliseconds(1)) {
expectUnreached()
}
assertNull(result)
result = withTimeoutOrNull(0.milliseconds) {
result = withTimeoutOrNull(Duration.milliseconds(0)) {
expectUnreached()
}
assertNull(result)
Expand All @@ -231,7 +232,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
expect(1)
try {
expect(2)
withTimeoutOrNull(1000.milliseconds) {
withTimeoutOrNull<Unit>(Duration.milliseconds(1000)) {
expect(3)
throw TestException()
}
Expand Down
3 changes: 2 additions & 1 deletion kotlinx-coroutines-core/common/test/WithTimeoutOrNullTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class WithTimeoutOrNullTest : TestBase() {

@Test
fun testThrowException() = runTest(expected = {it is AssertionError}) {
withTimeoutOrNull(Long.MAX_VALUE) {
withTimeoutOrNull<Unit>(Long.MAX_VALUE) {
throw AssertionError()
}
}
Expand All @@ -107,6 +107,7 @@ class WithTimeoutOrNullTest : TestBase() {
yield()
}
}
@Suppress("UNREACHABLE_CODE")
expectUnreached() // will timeout
}
expectUnreached() // will timeout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class CatchTest : TestBase() {
.flowOn(d2)
// flowOn with a different dispatcher introduces asynchrony so that all exceptions in the
// upstream flows are handled before they go downstream
.onEach { value ->
.onEach {
expectUnreached() // already cancelled
}
.catch { e ->
Expand Down

0 comments on commit 8baa736

Please sign in to comment.