Skip to content

Add overload with long for CoroutinesTimeout.seconds #1185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public final class kotlinx/coroutines/debug/junit4/CoroutinesTimeout : org/junit

public final class kotlinx/coroutines/debug/junit4/CoroutinesTimeout$Companion {
public final fun seconds (IZ)Lkotlinx/coroutines/debug/junit4/CoroutinesTimeout;
public final fun seconds (JZ)Lkotlinx/coroutines/debug/junit4/CoroutinesTimeout;
public static synthetic fun seconds$default (Lkotlinx/coroutines/debug/junit4/CoroutinesTimeout$Companion;IZILjava/lang/Object;)Lkotlinx/coroutines/debug/junit4/CoroutinesTimeout;
public static synthetic fun seconds$default (Lkotlinx/coroutines/debug/junit4/CoroutinesTimeout$Companion;JZILjava/lang/Object;)Lkotlinx/coroutines/debug/junit4/CoroutinesTimeout;
}

8 changes: 7 additions & 1 deletion kotlinx-coroutines-debug/src/junit4/CoroutinesTimeout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ public class CoroutinesTimeout(
* Creates [CoroutinesTimeout] rule with the given timeout in seconds.
*/
public fun seconds(seconds: Int, cancelOnTimeout: Boolean = false): CoroutinesTimeout =
CoroutinesTimeout(TimeUnit.SECONDS.toMillis(seconds.toLong()), cancelOnTimeout)
seconds(seconds.toLong(), cancelOnTimeout)

/**
* Creates [CoroutinesTimeout] rule with the given timeout in seconds.
*/
public fun seconds(seconds: Long, cancelOnTimeout: Boolean = false): CoroutinesTimeout =
CoroutinesTimeout(TimeUnit.SECONDS.toMillis(seconds), cancelOnTimeout) // Overflow is properly handled by TimeUnit
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ internal class CoroutinesTimeoutStatement(
"${testTimeoutMs / 1000} seconds"
else "$testTimeoutMs milliseconds"

val message = "Test ${description.methodName} timed out after $units"
System.err.println("\n$message\n")
System.err.println("\nTest ${description.methodName} timed out after $units\n")
System.err.flush()

DebugProbes.dumpCoroutines()
Expand All @@ -65,7 +64,7 @@ internal class CoroutinesTimeoutStatement(
* 2) Cancel all coroutines via debug agent API (changing system state!)
* 3) Throw created exception
*/
val exception = createTimeoutException(message, testThread)
val exception = createTimeoutException(testThread)
cancelIfNecessary()
// If timed out test throws an exception, we can't do much except ignoring it
throw exception
Expand All @@ -79,7 +78,7 @@ internal class CoroutinesTimeoutStatement(
}
}

private fun createTimeoutException(message: String, thread: Thread): Exception {
private fun createTimeoutException(thread: Thread): Exception {
val stackTrace = thread.stackTrace
val exception = TestTimedOutException(testTimeoutMs, TimeUnit.MILLISECONDS)
exception.stackTrace = stackTrace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package kotlinx.coroutines.debug.junit4

import junit4.*
import kotlinx.coroutines.*
import org.junit.*
import org.junit.runners.model.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package junit4
package kotlinx.coroutines.debug.junit4

import kotlinx.coroutines.debug.*
import kotlinx.coroutines.debug.junit4.*
import org.junit.rules.*
import org.junit.runner.*
import org.junit.runners.model.*
Expand Down