-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added PreInterruptCallback extension to allow to hook into the @timeout extension before the executing Thread is interrupted. The default implementation of PreInterruptCallback will simply print the stacks of all Thread to System.out. It is disabled by default and must be enabled with: junit.jupiter.execution.timeout.threaddump.enabled = true Issue: #2938 Co-authored-by: Marc Philipp <[email protected]>
- Loading branch information
1 parent
35d3dd7
commit 8e5b738
Showing
38 changed files
with
698 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/PreInterruptCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.jupiter.api.extension; | ||
|
||
import static org.apiguardian.api.API.Status.EXPERIMENTAL; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
/** | ||
* {@code PreInterruptCallback} defines the API for {@link Extension | ||
* Extensions} that wish to be called prior to invocations of | ||
* {@link Thread#interrupt()} by the {@link org.junit.jupiter.api.Timeout} | ||
* extension. | ||
* | ||
* <p>JUnit registers a default implementation that dumps the stacks of all | ||
* {@linkplain Thread threads} to {@code System.out} if the | ||
* {@value #THREAD_DUMP_ENABLED_PROPERTY_NAME} configuration parameter is set to | ||
* {@code true}. | ||
* | ||
* @since 5.12 | ||
* @see org.junit.jupiter.api.Timeout | ||
*/ | ||
@API(status = EXPERIMENTAL, since = "5.12") | ||
public interface PreInterruptCallback extends Extension { | ||
|
||
/** | ||
* Property name used to enable dumping the stack of all | ||
* {@linkplain Thread threads} to {@code System.out} when a timeout has occurred. | ||
* | ||
* <p>This behavior is disabled by default. | ||
* | ||
* @since 5.12 | ||
*/ | ||
@API(status = EXPERIMENTAL, since = "5.12") | ||
String THREAD_DUMP_ENABLED_PROPERTY_NAME = "junit.jupiter.execution.timeout.threaddump.enabled"; | ||
|
||
/** | ||
* Callback that is invoked <em>before</em> a {@link Thread} is interrupted with | ||
* {@link Thread#interrupt()}. | ||
* | ||
* <p>Note: There is no guarantee on which {@link Thread} this callback will be | ||
* executed. | ||
* | ||
* @param preInterruptContext the context with the target {@link Thread}, which will get interrupted. | ||
* @since 5.12 | ||
* @see PreInterruptContext | ||
*/ | ||
@API(status = EXPERIMENTAL, since = "5.12") | ||
void beforeThreadInterrupt(PreInterruptContext preInterruptContext) throws Exception; | ||
} |
44 changes: 44 additions & 0 deletions
44
junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/PreInterruptContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.jupiter.api.extension; | ||
|
||
import static org.apiguardian.api.API.Status.EXPERIMENTAL; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
/** | ||
* {@code PreInterruptContext} encapsulates the <em>context</em> in which an | ||
* {@link PreInterruptCallback#beforeThreadInterrupt(PreInterruptContext) beforeThreadInterrupt} method is called. | ||
* | ||
* @since 5.12 | ||
* @see PreInterruptCallback | ||
*/ | ||
@API(status = EXPERIMENTAL, since = "5.12") | ||
public interface PreInterruptContext { | ||
|
||
/** | ||
* Get the {@link Thread} which will be interrupted. | ||
* | ||
* @return the Thread; never {@code null} | ||
* @since 5.12 | ||
*/ | ||
@API(status = EXPERIMENTAL, since = "5.12") | ||
Thread getThreadToInterrupt(); | ||
|
||
/** | ||
* Get the current {@link ExtensionContext}. | ||
* | ||
* @return the current extension context; never {@code null} | ||
* @since 5.12 | ||
*/ | ||
@API(status = EXPERIMENTAL, since = "5.12") | ||
ExtensionContext getExtensionContext(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.