Skip to content

Commit

Permalink
Merge pull request #615 from jonesbusy/feature/exclude-slow-tests
Browse files Browse the repository at this point in the history
Reduce build time by skipping by default slow integration tests and use JUnit 5 Parallel execution for some classes
  • Loading branch information
jonesbusy authored Jan 11, 2025
2 parents 160adeb + b49bf0a commit ff513cb
Show file tree
Hide file tree
Showing 31 changed files with 141 additions and 10 deletions.
26 changes: 26 additions & 0 deletions plugin-modernizer-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<groups>Always</groups>
</configuration>
<executions>
<execution>
<id>integration-tests</id>
Expand Down Expand Up @@ -255,6 +258,29 @@
</build>

<profiles>
<profile>
<!-- Activate slow test that modernize samples plugins -->
<!-- Only run such test on CI and linux -->
<id>slow-tests</id>
<activation>
<os>
<family>unix</family>
</os>
<property>
<name>env.CI</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<groups>Always,Slow</groups>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>maven-repo-local</id>
<activation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@
import org.apache.maven.shared.invoker.Invoker;
import org.bouncycastle.openssl.jcajce.JcaPEMWriter;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.CleanupMode;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand All @@ -49,6 +52,7 @@
@WireMockTest
@Testcontainers(disabledWithoutDocker = true)
@ExtendWith(ModernizerTestWatcher.class)
@Execution(ExecutionMode.SAME_THREAD) // Need split or not using shared resources like logs folder
public class CommandLineITCase {

static {
Expand Down Expand Up @@ -125,6 +129,7 @@ public void beforeEach() throws Exception {
}

@Test
@Tag("Always")
public void testVersion() throws Exception {
Path logFile = setupLogs("testVersion");
Invoker invoker = buildInvoker();
Expand All @@ -147,6 +152,7 @@ public void testVersion() throws Exception {
}

@Test
@Tag("Always")
public void testHelp() throws Exception {
Path logFile = setupLogs("testHelp");
Invoker invoker = buildInvoker();
Expand All @@ -159,6 +165,7 @@ public void testHelp() throws Exception {
}

@Test
@Tag("Slow")
public void testCleanupWithDryRun() throws Exception {
Path logFile = setupLogs("testCleanupWithDryRun");
Invoker invoker = buildInvoker();
Expand All @@ -171,6 +178,7 @@ public void testCleanupWithDryRun() throws Exception {
}

@Test
@Tag("Slow")
public void testCleanup() throws Exception {
Path logFile = setupLogs("testCleanup");
Invoker invoker = buildInvoker();
Expand All @@ -183,6 +191,7 @@ public void testCleanup() throws Exception {
}

@Test
@Tag("Slow")
public void testValidateWithSshKey(WireMockRuntimeInfo wmRuntimeInfo) throws Exception {

Path logFile = setupLogs("testValidateWithSshKey");
Expand Down Expand Up @@ -211,6 +220,7 @@ public void testValidateWithSshKey(WireMockRuntimeInfo wmRuntimeInfo) throws Exc
}

@Test
@Tag("Slow")
public void testValidate(WireMockRuntimeInfo wmRuntimeInfo) throws Exception {

Path logFile = setupLogs("testValidate");
Expand All @@ -234,6 +244,7 @@ public void testValidate(WireMockRuntimeInfo wmRuntimeInfo) throws Exception {
}

@Test
@Tag("Slow")
public void testListRecipes() throws Exception {
Path logFile = setupLogs("testListRecipes");
Invoker invoker = buildInvoker();
Expand All @@ -250,6 +261,7 @@ public void testListRecipes() throws Exception {

@ParameterizedTest
@MethodSource("testsPlugins")
@Tag("Slow")
public void testBuildMetadata(PluginMetadata expectedMetadata, WireMockRuntimeInfo wmRuntimeInfo) throws Exception {

Path logFile = logFolder.resolve("testBuildMetadata-%s.txt".formatted(expectedMetadata.getPluginName()));
Expand Down Expand Up @@ -303,6 +315,7 @@ public void testBuildMetadata(PluginMetadata expectedMetadata, WireMockRuntimeIn
}

@Test
@Tag("Slow")
public void testDryRunReplaceLibrariesWithApiPlugin(WireMockRuntimeInfo wmRuntimeInfo) throws Exception {

Path logFile1 = setupLogs("testDryRunReplaceLibrariesWithApiPlugin1");
Expand Down Expand Up @@ -361,6 +374,7 @@ public void testDryRunReplaceLibrariesWithApiPlugin(WireMockRuntimeInfo wmRuntim
}

@Test
@Tag("Slow")
public void testRunAddDependabot(WireMockRuntimeInfo wmRuntimeInfo) throws Exception {

Path logFile = setupLogs("testRunAddDependabot");
Expand Down Expand Up @@ -401,6 +415,7 @@ public void testRunAddDependabot(WireMockRuntimeInfo wmRuntimeInfo) throws Excep
}

@Test
@Tag("Slow")
public void testDryRunAddDependabot(WireMockRuntimeInfo wmRuntimeInfo) throws Exception {

Path logFile = setupLogs("testDryRunAddDependabot");
Expand Down Expand Up @@ -442,6 +457,7 @@ public void testDryRunAddDependabot(WireMockRuntimeInfo wmRuntimeInfo) throws Ex
}

@Test
@Tag("Slow")
public void testRecipeOnLocalPlugin(WireMockRuntimeInfo wmRuntimeInfo) throws Exception {

Path logFile = setupLogs("testRecipeOnLocalPlugin");
Expand Down Expand Up @@ -487,6 +503,7 @@ public void testRecipeOnLocalPlugin(WireMockRuntimeInfo wmRuntimeInfo) throws Ex
}

@Test
@Tag("Slow")
public void testRecipeOnLocalPluginWithRunMode(WireMockRuntimeInfo wmRuntimeInfo) throws Exception {

Path logFile = setupLogs("testRecipeOnLocalPluginWithRunMode");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
junit.jupiter.execution.parallel.enabled=true
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
import java.util.List;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.mockito.Mockito;

@Execution(ExecutionMode.CONCURRENT)
public class ConfigTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import java.nio.file.Paths;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;
import uk.org.webcompere.systemstubs.jupiter.SystemStub;
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;

@ExtendWith(SystemStubsExtension.class)
@Execution(ExecutionMode.CONCURRENT)
public class SettingsEnvTest {

@SystemStub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import java.nio.file.Paths;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import uk.org.webcompere.systemstubs.jupiter.SystemStub;
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
import uk.org.webcompere.systemstubs.properties.SystemProperties;

@ExtendWith(SystemStubsExtension.class)
@Execution(ExecutionMode.CONCURRENT)
public class SettingsHomeDirTest {

@SystemStub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import java.nio.file.Paths;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import uk.org.webcompere.systemstubs.jupiter.SystemStub;
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
import uk.org.webcompere.systemstubs.properties.SystemProperties;

@ExtendWith(SystemStubsExtension.class)
@Execution(ExecutionMode.CONCURRENT)
public class SettingsUserDirTest {

@SystemStub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.openrewrite.Issue;
import org.openrewrite.java.JavaParser;
import org.openrewrite.test.RewriteTest;
Expand All @@ -30,6 +32,9 @@
/**
* Tests for {@link FetchMetadata}.
*/
// CacheManager is not thread safe. Test also manipulate shared metadata file.
// To fix at some point (maybe when adding concurrency in plugin modernizer)
@Execution(ExecutionMode.SAME_THREAD)
public class FetchMetadataTest implements RewriteTest {

private static final Logger LOG = LoggerFactory.getLogger(FetchMetadataTest.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.platform.commons.util.ReflectionUtils;
import org.kohsuke.github.GHCommitPointer;
import org.kohsuke.github.GHIssueState;
Expand All @@ -53,6 +55,7 @@
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith({MockitoExtension.class})
@Execution(ExecutionMode.CONCURRENT)
public class GHServiceTest {

@Mock
Expand All @@ -79,16 +82,17 @@ public class GHServiceTest {
public void setup() throws Exception {

// Create service
service = Guice.createInjector(new GuiceModule(config)).getInstance(GHService.class);

// Set github mock
Field field = ReflectionUtils.findFields(
GHService.class,
f -> f.getName().equals("github"),
ReflectionUtils.HierarchyTraversalMode.TOP_DOWN)
.get(0);
field.setAccessible(true);
field.set(service, github);
if (service == null) {
service = Guice.createInjector(new GuiceModule(config)).getInstance(GHService.class);
// Set github mock
Field field = ReflectionUtils.findFields(
GHService.class,
f -> f.getName().equals("github"),
ReflectionUtils.HierarchyTraversalMode.TOP_DOWN)
.get(0);
field.setAccessible(true);
field.set(service, github);
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

import java.util.Set;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;

@Execution(ExecutionMode.CONCURRENT)
public class JDKTest {

// Write tests for JDK enum here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
import java.nio.file.Path;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;

@ExtendWith(MockitoExtension.class)
@Execution(ExecutionMode.CONCURRENT)
public class PluginTest {

@Mock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.openrewrite.java.JavaParser;
import org.openrewrite.maven.MavenParser;
import org.openrewrite.test.RewriteTest;
Expand All @@ -30,6 +32,9 @@
/**
* Test for declarative recipes from recipes.yml.
*/
// ConcurrentModification on rewriteRun (need fix upstream?
// This only occur on recipeFromResource
@Execution(ExecutionMode.SAME_THREAD)
public class DeclarativeRecipesTest implements RewriteTest {

@Language("xml")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@

import io.jenkins.tools.pluginmodernizer.core.extractor.ArchetypeCommonFile;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.openrewrite.test.RewriteTest;

/**
* Test for {@link EnsureIndexJelly}.
*/
@Execution(ExecutionMode.CONCURRENT)
public class EnsureIndexJellyTest implements RewriteTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@

import io.jenkins.tools.pluginmodernizer.core.extractor.ArchetypeCommonFile;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

@Execution(ExecutionMode.CONCURRENT)
public class EnsureRelativePathTest implements RewriteTest {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

import io.jenkins.tools.pluginmodernizer.core.extractor.ArchetypeCommonFile;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.openrewrite.test.RewriteTest;

/**
* Test for {@link IsUsingArchetypeCommonFile}.
*/
@Execution(ExecutionMode.CONCURRENT)
public class IsUsingArchetypeCommonFileTest implements RewriteTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import static org.openrewrite.maven.Assertions.pomXml;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.openrewrite.test.RewriteTest;

/**
* Test for {@link IsUsingBom}.
*/
@Execution(ExecutionMode.CONCURRENT)
public class IsUsingBomTest implements RewriteTest {

@Test
Expand Down
Loading

0 comments on commit ff513cb

Please sign in to comment.