Skip to content

Commit

Permalink
Use spearate testkit dir for each run (#42013)
Browse files Browse the repository at this point in the history
Gradle Testkit reuses the teskit dir by default between tests.
With this change we use a temporary one for each run
hoping it will fix #41431
  • Loading branch information
alpar-t committed May 21, 2019
1 parent 216c74d commit de09648
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,35 @@

import org.elasticsearch.gradle.test.GradleIntegrationTestCase;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;


public class ExportElasticsearchBuildResourcesTaskIT extends GradleIntegrationTestCase {

public static final String PROJECT_NAME = "elasticsearch-build-resources";

public void testUpToDateWithSourcesConfigured() {
GradleRunner.create()
.withProjectDir(getProjectDir(PROJECT_NAME))
getGradleRunner(PROJECT_NAME)
.withArguments("clean", "-s")
.withPluginClasspath()
.build();

BuildResult result = GradleRunner.create()
.withProjectDir(getProjectDir(PROJECT_NAME))
BuildResult result = getGradleRunner(PROJECT_NAME)
.withArguments("buildResources", "-s", "-i")
.withPluginClasspath()
.build();
assertTaskSuccessful(result, ":buildResources");
assertBuildFileExists(result, PROJECT_NAME, "build-tools-exported/checkstyle.xml");
assertBuildFileExists(result, PROJECT_NAME, "build-tools-exported/checkstyle_suppressions.xml");

result = GradleRunner.create()
.withProjectDir(getProjectDir(PROJECT_NAME))
result = getGradleRunner(PROJECT_NAME)
.withArguments("buildResources", "-s", "-i")
.withPluginClasspath()
.build();
assertTaskUpToDate(result, ":buildResources");
assertBuildFileExists(result, PROJECT_NAME, "build-tools-exported/checkstyle.xml");
assertBuildFileExists(result, PROJECT_NAME, "build-tools-exported/checkstyle_suppressions.xml");
}

public void testImplicitTaskDependencyCopy() {
BuildResult result = GradleRunner.create()
.withProjectDir(getProjectDir(PROJECT_NAME))
BuildResult result = getGradleRunner(PROJECT_NAME)
.withArguments("clean", "sampleCopyAll", "-s", "-i")
.withPluginClasspath()
.build();

assertTaskSuccessful(result, ":buildResources");
Expand All @@ -69,10 +60,8 @@ public void testImplicitTaskDependencyCopy() {
}

public void testImplicitTaskDependencyInputFileOfOther() {
BuildResult result = GradleRunner.create()
.withProjectDir(getProjectDir(PROJECT_NAME))
BuildResult result = getGradleRunner(PROJECT_NAME)
.withArguments("clean", "sample", "-s", "-i")
.withPluginClasspath()
.build();

assertTaskSuccessful(result, ":sample");
Expand All @@ -81,11 +70,12 @@ public void testImplicitTaskDependencyInputFileOfOther() {
}

public void testIncorrectUsage() {
BuildResult result = GradleRunner.create()
.withProjectDir(getProjectDir(PROJECT_NAME))
.withArguments("noConfigAfterExecution", "-s", "-i")
.withPluginClasspath()
.buildAndFail();
assertOutputContains("buildResources can't be configured after the task ran");
assertOutputContains(
getGradleRunner(PROJECT_NAME)
.withArguments("noConfigAfterExecution", "-s", "-i")
.buildAndFail()
.getOutput(),
"buildResources can't be configured after the task ran"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.elasticsearch.gradle.test.GradleIntegrationTestCase;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;

/*
* Licensed to Elasticsearch under one or more contributor
Expand All @@ -25,10 +24,8 @@
public class JarHellTaskIT extends GradleIntegrationTestCase {

public void testJarHellDetected() {
BuildResult result = GradleRunner.create()
.withProjectDir(getProjectDir("jarHell"))
BuildResult result = getGradleRunner("jarHell")
.withArguments("clean", "precommit", "-s", "-Dlocal.repo.path=" + getLocalTestRepoPath())
.withPluginClasspath()
.buildAndFail();

assertTaskFailed(result, ":jarHell");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import org.gradle.testkit.runner.TaskOutcome;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;

import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
Expand All @@ -16,6 +20,9 @@

public abstract class GradleIntegrationTestCase extends GradleUnitTestCase {

@Rule
public TemporaryFolder testkitTmpDir = new TemporaryFolder();

protected File getProjectDir(String name) {
File root = new File("src/testKit/");
if (root.exists() == false) {
Expand All @@ -26,9 +33,16 @@ protected File getProjectDir(String name) {
}

protected GradleRunner getGradleRunner(String sampleProject) {
File testkit;
try {
testkit = testkitTmpDir.newFolder();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return GradleRunner.create()
.withProjectDir(getProjectDir(sampleProject))
.withPluginClasspath();
.withPluginClasspath()
.withTestKitDir(testkit);
}

protected File getBuildDir(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@
import org.elasticsearch.gradle.test.GradleIntegrationTestCase;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.Before;
import org.junit.Ignore;


import java.util.Arrays;

public class TestClustersPluginIT extends GradleIntegrationTestCase {

private GradleRunner runner;

@Before
public void setUp() throws Exception {
runner = getGradleRunner("testclusters");
}

public void testListClusters() {
BuildResult result = getTestClustersRunner("listTestClusters").build();

Expand Down Expand Up @@ -190,10 +199,7 @@ private GradleRunner getTestClustersRunner(String... tasks) {
arguments[tasks.length] = "-s";
arguments[tasks.length + 1] = "-i";
arguments[tasks.length + 2] = "-Dlocal.repo.path=" + getLocalTestRepoPath();
return GradleRunner.create()
.withProjectDir(getProjectDir("testclusters"))
.withArguments(arguments)
.withPluginClasspath();
return runner.withArguments(arguments);
}

private void assertStartedAndStoppedOnce(BuildResult result, String nodeName) {
Expand Down

0 comments on commit de09648

Please sign in to comment.