Skip to content
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

Ensure JenkinsRule#after() is called even when timeout is reached #264

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
37 changes: 15 additions & 22 deletions src/main/java/org/jvnet/hudson/test/JenkinsRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,15 @@ public Statement apply(final Statement base, final Description description) {
// request has been made to not create the instance for this test method
return base;
}
Statement wrapped = new Statement() {
Statement wrappedBase;
final int testTimeout = getTestTimeoutOverride(description);
if (testTimeout <= 0) {
System.out.println("Test timeout disabled.");
wrappedBase = base;
} else {
wrappedBase = Timeout.seconds(testTimeout).apply(base, description);
}
return new Statement() {
@Override
public void evaluate() throws Throwable {
testDescription = description;
Expand All @@ -703,7 +711,12 @@ public void evaluate() throws Throwable {
// so that test code has all the access to the system
ACL.impersonate(ACL.SYSTEM);
try {
base.evaluate();
wrappedBase.evaluate();
} catch (TestTimedOutException x) {
// withLookingForStuckThread does not work well; better to just have a full thread dump.
LOGGER.warning(String.format("Test timed out (after %d seconds).", testTimeout));
dumpThreads();
throw x;
} catch (Throwable th) {
testFailure = th;
// allow the late attachment of a debugger in case of a failure. Useful
Expand Down Expand Up @@ -737,26 +750,6 @@ public void evaluate() throws Throwable {
}
}
};
final int testTimeout = getTestTimeoutOverride(description);
if (testTimeout <= 0) {
System.out.println("Test timeout disabled.");
return wrapped;
} else {
final Statement timeoutStatement = Timeout.seconds(testTimeout).apply(wrapped, description);
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
timeoutStatement.evaluate();
} catch (TestTimedOutException x) {
// withLookingForStuckThread does not work well; better to just have a full thread dump.
LOGGER.warning(String.format("Test timed out (after %d seconds).", testTimeout));
dumpThreads();
throw x;
}
}
};
}
}

private int getTestTimeoutOverride(Description description) {
Expand Down