Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dkhalanskyjb committed Apr 23, 2021
1 parent 6c1d6e7 commit bb5216c
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 40 deletions.
22 changes: 0 additions & 22 deletions kotlinx-coroutines-debug/api/kotlinx-coroutines-debug.api
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,3 @@ public abstract interface annotation class kotlinx/coroutines/debug/junit5/Corou
public abstract fun testTimeoutMs ()J
}

public final class kotlinx/coroutines/debug/junit5/CoroutinesTimeoutExtension : org/junit/jupiter/api/extension/InvocationInterceptor {
public static final field Companion Lkotlinx/coroutines/debug/junit5/CoroutinesTimeoutExtension$Companion;
public fun <init> ()V
public fun <init> (JZZ)V
public synthetic fun <init> (JZZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun interceptAfterAllMethod (Lorg/junit/jupiter/api/extension/InvocationInterceptor$Invocation;Lorg/junit/jupiter/api/extension/ReflectiveInvocationContext;Lorg/junit/jupiter/api/extension/ExtensionContext;)V
public fun interceptAfterEachMethod (Lorg/junit/jupiter/api/extension/InvocationInterceptor$Invocation;Lorg/junit/jupiter/api/extension/ReflectiveInvocationContext;Lorg/junit/jupiter/api/extension/ExtensionContext;)V
public fun interceptBeforeAllMethod (Lorg/junit/jupiter/api/extension/InvocationInterceptor$Invocation;Lorg/junit/jupiter/api/extension/ReflectiveInvocationContext;Lorg/junit/jupiter/api/extension/ExtensionContext;)V
public fun interceptBeforeEachMethod (Lorg/junit/jupiter/api/extension/InvocationInterceptor$Invocation;Lorg/junit/jupiter/api/extension/ReflectiveInvocationContext;Lorg/junit/jupiter/api/extension/ExtensionContext;)V
public fun interceptTestClassConstructor (Lorg/junit/jupiter/api/extension/InvocationInterceptor$Invocation;Lorg/junit/jupiter/api/extension/ReflectiveInvocationContext;Lorg/junit/jupiter/api/extension/ExtensionContext;)Ljava/lang/Object;
public fun interceptTestFactoryMethod (Lorg/junit/jupiter/api/extension/InvocationInterceptor$Invocation;Lorg/junit/jupiter/api/extension/ReflectiveInvocationContext;Lorg/junit/jupiter/api/extension/ExtensionContext;)Ljava/lang/Object;
public fun interceptTestMethod (Lorg/junit/jupiter/api/extension/InvocationInterceptor$Invocation;Lorg/junit/jupiter/api/extension/ReflectiveInvocationContext;Lorg/junit/jupiter/api/extension/ExtensionContext;)V
public fun interceptTestTemplateMethod (Lorg/junit/jupiter/api/extension/InvocationInterceptor$Invocation;Lorg/junit/jupiter/api/extension/ReflectiveInvocationContext;Lorg/junit/jupiter/api/extension/ExtensionContext;)V
}

public final class kotlinx/coroutines/debug/junit5/CoroutinesTimeoutExtension$Companion {
public final fun seconds (I)Lkotlinx/coroutines/debug/junit5/CoroutinesTimeoutExtension;
public final fun seconds (IZ)Lkotlinx/coroutines/debug/junit5/CoroutinesTimeoutExtension;
public final fun seconds (IZZ)Lkotlinx/coroutines/debug/junit5/CoroutinesTimeoutExtension;
public static synthetic fun seconds$default (Lkotlinx/coroutines/debug/junit5/CoroutinesTimeoutExtension$Companion;IZZILjava/lang/Object;)Lkotlinx/coroutines/debug/junit5/CoroutinesTimeoutExtension;
}

2 changes: 1 addition & 1 deletion kotlinx-coroutines-debug/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if (rootProject.ext.jvm_ir_enabled) {

java {
/* This is needed to be able to run JUnit5 tests. Otherwise, Gradle complains that it can't find the
JVM1.6-compatible version of the `junit-platform-testkit` artifact. */
JVM1.6-compatible version of the `junit-jupiter-api` artifact. */
disableAutoTargetJvm()
}

Expand Down
12 changes: 3 additions & 9 deletions kotlinx-coroutines-debug/src/junit/junit5/CoroutinesTimeout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ import java.lang.annotation.*
* separate thread, failing them after the provided time limit and interrupting the thread.
*
* Additionally, it installs [DebugProbes] and dumps all coroutines at the moment of the timeout. It also cancels
* coroutines on timeout if [cancelOnTimeout] set to `true`. The dump contains the coroutine creation stack traces. If
* there is need to disable the creation stack traces in order to speed tests up, consider directly using
* [CoroutinesTimeoutExtension], which allows such configuration.
* coroutines on timeout if [cancelOnTimeout] set to `true`. The dump contains the coroutine creation stack traces.
*
* This annotation registers [CoroutinesTimeoutExtension] on test, test factory, test template, and lifecycle methods
* and test classes that are annotated with it.
* This annotation has an effect on test, test factory, test template, and lifecycle methods and test classes that are
* annotated with it.
*
* Annotating a class is the same as annotating every test, test factory, and test template method (but not lifecycle
* methods) of that class and its inner test classes, unless any of them is annotated with [CoroutinesTimeout], in which
Expand All @@ -28,9 +26,6 @@ import java.lang.annotation.*
* Declaring [CoroutinesTimeout] on a test factory checks that it finishes in the specified time, but does not check
* whether the methods that it produces obey the timeout as well.
*
* Beware that registering the extension via this annotation conflicts with manually registering the extension on the
* same tests via other methods (most notably, [RegisterExtension]) and is prohibited.
*
* Example usage:
* ```
* @CoroutinesTimeout(100)
Expand All @@ -55,7 +50,6 @@ import java.lang.annotation.*
* ```
*
* @see Timeout
* @see CoroutinesTimeoutExtension
*/
@ExtendWith(CoroutinesTimeoutExtension::class)
@Inherited
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ internal class CoroutinesTimeoutException(val timeoutMs: Long): Exception("test
* @see [CoroutinesTimeout]
* */
// NB: the constructor is not private so that JUnit is able to call it via reflection.
public class CoroutinesTimeoutExtension internal constructor(
internal class CoroutinesTimeoutExtension internal constructor(
private val enableCoroutineCreationStackTraces: Boolean = true,
private val timeoutMs: Long? = null,
private val cancelOnTimeout: Boolean? = null): InvocationInterceptor
Expand All @@ -81,9 +81,6 @@ public class CoroutinesTimeoutExtension internal constructor(

private fun tryPassDebugProbesOwnership() = debugProbesOwnershipPassed.compareAndSet(false, true)

private val isDebugProbesOwnershipPassed
get() = debugProbesOwnershipPassed.get()

/* We install the debug probes early so that the coroutines launched from the test constructor are captured as well.
However, this is not enough as the same extension instance may be reused several times, even cleaning up its
resources from the store. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CoroutinesTimeoutExtensionTest {
class DisabledStackTracesTest {
@JvmField
@RegisterExtension
val timeout = CoroutinesTimeoutExtension(500, true, false)
internal val timeout = CoroutinesTimeoutExtension(500, true, false)

private val job = GlobalScope.launch(Dispatchers.Unconfined) { hangForever() }

Expand Down Expand Up @@ -55,7 +55,7 @@ class CoroutinesTimeoutExtensionTest {

@JvmField
@RegisterExtension
val timeout = CoroutinesTimeoutExtension(500)
internal val timeout = CoroutinesTimeoutExtension(500)

private val job = GlobalScope.launch(Dispatchers.Unconfined) { hangForever() }

Expand Down Expand Up @@ -87,7 +87,7 @@ class CoroutinesTimeoutExtensionTest {

@JvmField
@RegisterExtension
public val timeout = CoroutinesTimeoutExtension(1000, false, true)
internal val timeout = CoroutinesTimeoutExtension(1000, false, true)

@Test
fun hangingTest() = runBlocking<Unit> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.junit.jupiter.api.extension.*
class RegisterExtensionExample {
@JvmField
@RegisterExtension
val timeout = CoroutinesTimeoutExtension.seconds(5)
internal val timeout = CoroutinesTimeoutExtension.seconds(5)

@Test
fun testThatHangs() = runBlocking {
Expand Down

0 comments on commit bb5216c

Please sign in to comment.