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

Add timeout config parameter #2026

Merged
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.engine.AbstractJupiterTestEngineTests;
import org.junit.platform.commons.PreconditionViolationException;
import org.junit.platform.commons.util.RuntimeUtils;
import org.junit.platform.testkit.engine.EngineExecutionResults;
import org.junit.platform.testkit.engine.Events;
import org.junit.platform.testkit.engine.Execution;
Expand Down Expand Up @@ -88,6 +89,33 @@ void doesNotApplyTimeoutOnAnnotatedTestMethodsUsingDisabledTimeoutMode() {
.isEmpty();
}

@Test
@DisplayName("is not applied on annotated @Test methods using timeout mode: disabled")
void applyTimeoutOnAnnotatedTestMethodsUsingDisabledOnDebugTimeoutMode() {
EngineExecutionResults results = executeTests(request() //
.selectors(selectMethod(TimeoutAnnotatedTestMethodTestCase.class, "testMethod")) //
.configurationParameter(DEFAULT_TEST_METHOD_TIMEOUT_PROPERTY_NAME, "42ns") //
.configurationParameter(TIMEOUT_MODE_PROPERTY_NAME, "disabled_on_debug").build());

Execution execution = findExecution(results.testEvents(), "testMethod()");

assertThat(execution.getDuration()) //
.isGreaterThanOrEqualTo(Duration.ofMillis(10)) //
// The check to see if debugging is pushing the timer just above 1 second
.isLessThan(Duration.ofSeconds(2));

// Should we test if we're debugging? This test will fail if we are debugging.
if (RuntimeUtils.isDebug()) {
assertThat(execution.getTerminationInfo().getExecutionResult().getThrowable()) //
.isEmpty();
}
else {
assertThat(execution.getTerminationInfo().getExecutionResult().getThrowable().orElseThrow()) //
.isInstanceOf(TimeoutException.class) //
.hasMessage("testMethod() timed out after 10 milliseconds");
}
chrischild marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
@DisplayName("is applied on annotated @TestTemplate methods")
void appliesTimeoutOnAnnotatedTestTemplateMethods() {
Expand Down