Use spearate testkit dir for each run (#42013)

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
This commit is contained in:
Alpar Torok 2019-05-21 13:49:42 +03:00
parent 216c74d10a
commit de096485c8
4 changed files with 38 additions and 31 deletions

View File

@ -21,7 +21,6 @@ package org.elasticsearch.gradle;
import org.elasticsearch.gradle.test.GradleIntegrationTestCase; import org.elasticsearch.gradle.test.GradleIntegrationTestCase;
import org.gradle.testkit.runner.BuildResult; import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;
public class ExportElasticsearchBuildResourcesTaskIT extends GradleIntegrationTestCase { public class ExportElasticsearchBuildResourcesTaskIT extends GradleIntegrationTestCase {
@ -29,25 +28,19 @@ public class ExportElasticsearchBuildResourcesTaskIT extends GradleIntegrationTe
public static final String PROJECT_NAME = "elasticsearch-build-resources"; public static final String PROJECT_NAME = "elasticsearch-build-resources";
public void testUpToDateWithSourcesConfigured() { public void testUpToDateWithSourcesConfigured() {
GradleRunner.create() getGradleRunner(PROJECT_NAME)
.withProjectDir(getProjectDir(PROJECT_NAME))
.withArguments("clean", "-s") .withArguments("clean", "-s")
.withPluginClasspath()
.build(); .build();
BuildResult result = GradleRunner.create() BuildResult result = getGradleRunner(PROJECT_NAME)
.withProjectDir(getProjectDir(PROJECT_NAME))
.withArguments("buildResources", "-s", "-i") .withArguments("buildResources", "-s", "-i")
.withPluginClasspath()
.build(); .build();
assertTaskSuccessful(result, ":buildResources"); assertTaskSuccessful(result, ":buildResources");
assertBuildFileExists(result, PROJECT_NAME, "build-tools-exported/checkstyle.xml"); assertBuildFileExists(result, PROJECT_NAME, "build-tools-exported/checkstyle.xml");
assertBuildFileExists(result, PROJECT_NAME, "build-tools-exported/checkstyle_suppressions.xml"); assertBuildFileExists(result, PROJECT_NAME, "build-tools-exported/checkstyle_suppressions.xml");
result = GradleRunner.create() result = getGradleRunner(PROJECT_NAME)
.withProjectDir(getProjectDir(PROJECT_NAME))
.withArguments("buildResources", "-s", "-i") .withArguments("buildResources", "-s", "-i")
.withPluginClasspath()
.build(); .build();
assertTaskUpToDate(result, ":buildResources"); assertTaskUpToDate(result, ":buildResources");
assertBuildFileExists(result, PROJECT_NAME, "build-tools-exported/checkstyle.xml"); assertBuildFileExists(result, PROJECT_NAME, "build-tools-exported/checkstyle.xml");
@ -55,10 +48,8 @@ public class ExportElasticsearchBuildResourcesTaskIT extends GradleIntegrationTe
} }
public void testImplicitTaskDependencyCopy() { public void testImplicitTaskDependencyCopy() {
BuildResult result = GradleRunner.create() BuildResult result = getGradleRunner(PROJECT_NAME)
.withProjectDir(getProjectDir(PROJECT_NAME))
.withArguments("clean", "sampleCopyAll", "-s", "-i") .withArguments("clean", "sampleCopyAll", "-s", "-i")
.withPluginClasspath()
.build(); .build();
assertTaskSuccessful(result, ":buildResources"); assertTaskSuccessful(result, ":buildResources");
@ -69,10 +60,8 @@ public class ExportElasticsearchBuildResourcesTaskIT extends GradleIntegrationTe
} }
public void testImplicitTaskDependencyInputFileOfOther() { public void testImplicitTaskDependencyInputFileOfOther() {
BuildResult result = GradleRunner.create() BuildResult result = getGradleRunner(PROJECT_NAME)
.withProjectDir(getProjectDir(PROJECT_NAME))
.withArguments("clean", "sample", "-s", "-i") .withArguments("clean", "sample", "-s", "-i")
.withPluginClasspath()
.build(); .build();
assertTaskSuccessful(result, ":sample"); assertTaskSuccessful(result, ":sample");
@ -81,11 +70,12 @@ public class ExportElasticsearchBuildResourcesTaskIT extends GradleIntegrationTe
} }
public void testIncorrectUsage() { public void testIncorrectUsage() {
BuildResult result = GradleRunner.create() assertOutputContains(
.withProjectDir(getProjectDir(PROJECT_NAME)) getGradleRunner(PROJECT_NAME)
.withArguments("noConfigAfterExecution", "-s", "-i") .withArguments("noConfigAfterExecution", "-s", "-i")
.withPluginClasspath() .buildAndFail()
.buildAndFail(); .getOutput(),
assertOutputContains("buildResources can't be configured after the task ran"); "buildResources can't be configured after the task ran"
);
} }
} }

View File

@ -2,7 +2,6 @@ package org.elasticsearch.gradle.precommit;
import org.elasticsearch.gradle.test.GradleIntegrationTestCase; import org.elasticsearch.gradle.test.GradleIntegrationTestCase;
import org.gradle.testkit.runner.BuildResult; import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;
/* /*
* Licensed to Elasticsearch under one or more contributor * Licensed to Elasticsearch under one or more contributor
@ -25,10 +24,8 @@ import org.gradle.testkit.runner.GradleRunner;
public class JarHellTaskIT extends GradleIntegrationTestCase { public class JarHellTaskIT extends GradleIntegrationTestCase {
public void testJarHellDetected() { public void testJarHellDetected() {
BuildResult result = GradleRunner.create() BuildResult result = getGradleRunner("jarHell")
.withProjectDir(getProjectDir("jarHell"))
.withArguments("clean", "precommit", "-s", "-Dlocal.repo.path=" + getLocalTestRepoPath()) .withArguments("clean", "precommit", "-s", "-Dlocal.repo.path=" + getLocalTestRepoPath())
.withPluginClasspath()
.buildAndFail(); .buildAndFail();
assertTaskFailed(result, ":jarHell"); assertTaskFailed(result, ":jarHell");

View File

@ -4,8 +4,12 @@ import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask; import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner; import org.gradle.testkit.runner.GradleRunner;
import org.gradle.testkit.runner.TaskOutcome; import org.gradle.testkit.runner.TaskOutcome;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List; import java.util.List;
@ -16,6 +20,9 @@ import java.util.stream.Stream;
public abstract class GradleIntegrationTestCase extends GradleUnitTestCase { public abstract class GradleIntegrationTestCase extends GradleUnitTestCase {
@Rule
public TemporaryFolder testkitTmpDir = new TemporaryFolder();
protected File getProjectDir(String name) { protected File getProjectDir(String name) {
File root = new File("src/testKit/"); File root = new File("src/testKit/");
if (root.exists() == false) { if (root.exists() == false) {
@ -26,9 +33,16 @@ public abstract class GradleIntegrationTestCase extends GradleUnitTestCase {
} }
protected GradleRunner getGradleRunner(String sampleProject) { protected GradleRunner getGradleRunner(String sampleProject) {
File testkit;
try {
testkit = testkitTmpDir.newFolder();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return GradleRunner.create() return GradleRunner.create()
.withProjectDir(getProjectDir(sampleProject)) .withProjectDir(getProjectDir(sampleProject))
.withPluginClasspath(); .withPluginClasspath()
.withTestKitDir(testkit);
} }
protected File getBuildDir(String name) { protected File getBuildDir(String name) {

View File

@ -21,12 +21,21 @@ package org.elasticsearch.gradle.testclusters;
import org.elasticsearch.gradle.test.GradleIntegrationTestCase; import org.elasticsearch.gradle.test.GradleIntegrationTestCase;
import org.gradle.testkit.runner.BuildResult; import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner; import org.gradle.testkit.runner.GradleRunner;
import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import java.util.Arrays; import java.util.Arrays;
public class TestClustersPluginIT extends GradleIntegrationTestCase { public class TestClustersPluginIT extends GradleIntegrationTestCase {
private GradleRunner runner;
@Before
public void setUp() throws Exception {
runner = getGradleRunner("testclusters");
}
public void testListClusters() { public void testListClusters() {
BuildResult result = getTestClustersRunner("listTestClusters").build(); BuildResult result = getTestClustersRunner("listTestClusters").build();
@ -190,10 +199,7 @@ public class TestClustersPluginIT extends GradleIntegrationTestCase {
arguments[tasks.length] = "-s"; arguments[tasks.length] = "-s";
arguments[tasks.length + 1] = "-i"; arguments[tasks.length + 1] = "-i";
arguments[tasks.length + 2] = "-Dlocal.repo.path=" + getLocalTestRepoPath(); arguments[tasks.length + 2] = "-Dlocal.repo.path=" + getLocalTestRepoPath();
return GradleRunner.create() return runner.withArguments(arguments);
.withProjectDir(getProjectDir("testclusters"))
.withArguments(arguments)
.withPluginClasspath();
} }
private void assertStartedAndStoppedOnce(BuildResult result, String nodeName) { private void assertStartedAndStoppedOnce(BuildResult result, String nodeName) {