GeezerVison is showing github.com — Implement fail-fast behavior for JUnit Platform provider by marcphilipp · Pull Request #3155 · apache/maven-surefire
Implement fail-fast behavior for JUnit Platform provider
#3155
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
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension
.java
(21)
.vm
(1)
.xml
(1)
All 3 file types selected
Only manifest files
Deleted files
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -41,8 +41,8 @@ Skipping Tests After the Nth Failure or Error
Prerequisite
Use ${project.artifactId} 2.19 or higher, JUnit 4.0 or higher, or
TestNG 5.10 or higher.
Use ${project.artifactId} 2.19 or higher, JUnit 4.0 or higher, TestNG 5.10 or
higher, or JUnit Platform 6.0 or higher.
If version of TestNG is lower than 5.10 while the parameter
<<<skipAfterFailureCount>>> is set, the plugin fails with error:
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -16,17 +16,24 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.surefire.testng.utils;
import org.apache.maven.surefire.api.report.RunListener;
package org.apache.maven.surefire.api.report;
/**
* Covers configuration parameter {@code skipAfterFailureCount}.
*
* @author <a href="mailto:[email protected] ">Tibor Digana (tibor17)</a>
* @since 2.19
*/
@FunctionalInterface
public interface Stoppable {
/**
* Null object for use when fail-fast behavior is disabled.
*/
Stoppable NOOP = () -> {
// do nothing
};
/**
* Delegates this call to {@link RunListener#testExecutionSkippedByUser()}.
*/
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -110,8 +110,14 @@ static Map<String, String> props(int forkCount, int skipAfterFailureCount, boole
@Test
public void test() throws Exception {
String cls = useProcessPipes ? LEGACY_FORK_NODE : SUREFIRE_FORK_NODE;
prepare(description, profile, properties)
OutputValidator validator = prepare(description, profile, properties);
validator
.assertTestSuiteResults(total, errors, failures, skipped)
.assertThatLogLine(containsString("Found implementation of fork node factory: " + cls), equalTo(1));
performExtraChecks(validator);
}
protected void performExtraChecks(OutputValidator validator) throws Exception {
// may be overriden in subclasses
}
}
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,85 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.surefire.its;
import java.util.Arrays;
import java.util.Map;
import org.apache.maven.surefire.its.fixture.OutputValidator;
import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;
import static java.lang.Integer.parseInt;
import static org.apache.maven.surefire.its.fixture.HelperAssertions.assumeJavaVersion;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
public class FailFastJUnitPlatformIT extends AbstractFailFastIT {
@Parameters(name = "{0}")
public static Iterable<Object[]> data() {
// description profile forkCount,
// | | | fail-fast-count,
// | | | | reuseForks
// | | | | | total
// | | | | | | failures
// | | | | | | | errors
// | | | | | | | | skipped
// | | | | | | | | | pipes
return Arrays.asList( // | | | | | | | | |
new Object[] {"oneFork-ff1", null, props(1, 1, true), 5, 0, 1, 4, true},
new Object[] {"oneFork-ff2", null, props(1, 2, true), 5, 0, 2, 3, true},
new Object[] {"twoForks-ff1", null, props(2, 1, true), 5, 0, 2, 3, true},
new Object[] {"twoForks-ff2", null, props(2, 2, true), 5, 0, 2, 2, true},
new Object[] {"oneFork-ff3", null, props(1, 3, true), 5, 0, 2, 0, true},
new Object[] {"twoForks-ff3", null, props(2, 3, true), 5, 0, 2, 0, true},
new Object[] {
"unsupported-version", null, withUnsupportedJUnitVersion(props(2, 1, true)), 5, 0, 2, 0, true
});
}
private static Map<String, String> withUnsupportedJUnitVersion(Map<String, String> props) {
props.put("junit.version", "5.13.3");
return props;
}
@Override
protected String withProvider() {
return "junit-platform";
}
@Override
@Test
public void test() throws Exception {
if (!"unsupported-version".equals(description)) {
// JUnit 6.0.0 requires Java 17+
assumeJavaVersion(17);
}
super.test();
}
@Override
protected void performExtraChecks(OutputValidator validator) throws Exception {
if ("unsupported-version".equals(description)) {
int forkCount = parseInt(properties.get("forkCount"));
validator.assertThatLogLine(
containsString("An attempt was made to cancel the current test run"), equalTo(forkCount));
}
}
}
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.plugins.surefire</groupId>
<artifactId>fail-fast-junit-platform</artifactId>
<version>1.0</version>
<properties>
<maven.compiler.release>${java.specification.version}</maven.compiler.release>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<junit.version>6.0.0-M2</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<configuration>
<runOrder>alphabetical</runOrder>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.0</version>
</plugin>
</plugins>
</build>
</project>
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,13 @@
package pkg;
import org.junit.jupiter.api.Test;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
class ATest {
@Test
void test() throws Exception {
MILLISECONDS.sleep(1_000);
throw new RuntimeException();
}
}
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,13 @@
package pkg;
import org.junit.jupiter.api.Test;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
class BTest {
@Test
void test() throws Exception {
MILLISECONDS.sleep(2_000);
throw new RuntimeException();
}
}
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,12 @@
package pkg;
import org.junit.jupiter.api.Test;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
class CTest {
@Test
void test() throws Exception {
MILLISECONDS.sleep(2_000);
}
}
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,11 @@
package pkg;
import org.junit.jupiter.api.Test;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
class DTest {
@Test
void test() {
}
}
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,11 @@
package pkg;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import org.junit.jupiter.api.Test;
class ETest {
@Test
void test() {
}
}
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,54 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.surefire.junitplatform;
import java.lang.reflect.Method;
import org.apache.maven.surefire.api.util.ReflectionUtils;
import org.junit.platform.engine.ExecutionRequest;
class CancellationTokenAdapter {
static final Class<?> CANCELLATION_TOKEN_CLASS = ReflectionUtils.tryLoadClass(
ExecutionRequest.class.getClassLoader(), "org.junit.platform.engine.CancellationToken");
static CancellationTokenAdapter tryCreate() {
if (CANCELLATION_TOKEN_CLASS == null) {
return null;
}
Method createMethod = ReflectionUtils.getMethod(CANCELLATION_TOKEN_CLASS, "create");
Object token = ReflectionUtils.invokeMethodWithArray(null, createMethod);
return new CancellationTokenAdapter(token);
}
private final Object delegate;
private CancellationTokenAdapter(Object delegate) {
this.delegate = delegate;
}
Object getDelegate() {
return delegate;
}
void cancel() {
Method cancelMethod = ReflectionUtils.getMethod(CANCELLATION_TOKEN_CLASS, "cancel");
ReflectionUtils.invokeMethodWithArray(delegate, cancelMethod);
}
}
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.