Add explicit build flag for experimenting with test execution cacheability (#42649)

* Add build flag for ignoring random test seed as task input

* Fix checkstyle violations
This commit is contained in:
Mark Vieira 2019-05-28 17:52:35 -07:00 committed by Alpar Torok
parent 7bc86f23ec
commit ef0b75765b
3 changed files with 63 additions and 41 deletions

View File

@ -843,7 +843,7 @@ class BuildPlugin implements Plugin<Project> {
}
test.jvmArgumentProviders.add(nonInputProperties)
test.extensions.getByType(ExtraPropertiesExtension).set('nonInputProperties', nonInputProperties)
test.extensions.add('nonInputProperties', nonInputProperties)
test.executable = "${ext.get('runtimeJavaHome')}/bin/java"
test.workingDir = project.file("${project.buildDir}/testrun/${test.name}")
@ -865,7 +865,8 @@ class BuildPlugin implements Plugin<Project> {
}
// we use './temp' since this is per JVM and tests are forbidden from writing to CWD
test.systemProperties 'java.io.tmpdir': './temp',
test.systemProperties 'gradle.dist.lib': new File(project.class.location.toURI()).parent,
'java.io.tmpdir': './temp',
'java.awt.headless': 'true',
'tests.gradle': 'true',
'tests.artifact': project.name,
@ -881,7 +882,6 @@ class BuildPlugin implements Plugin<Project> {
}
// don't track these as inputs since they contain absolute paths and break cache relocatability
nonInputProperties.systemProperty('gradle.dist.lib', new File(project.class.location.toURI()).parent)
nonInputProperties.systemProperty('gradle.worker.jar', "${project.gradle.getGradleUserHomeDir()}/caches/${project.gradle.gradleVersion}/workerMain/gradle-worker.jar")
nonInputProperties.systemProperty('gradle.user.home', project.gradle.getGradleUserHomeDir())
@ -1007,19 +1007,4 @@ class BuildPlugin implements Plugin<Project> {
})
}
}
private static class SystemPropertyCommandLineArgumentProvider implements CommandLineArgumentProvider {
private final Map<String, Object> systemProperties = [:]
void systemProperty(String key, Object value) {
systemProperties.put(key, value)
}
@Override
Iterable<String> asArguments() {
return systemProperties.collect { key, value ->
"-D${key}=${value.toString()}".toString()
}
}
}
}

View File

@ -0,0 +1,30 @@
package org.elasticsearch.gradle;
import org.gradle.api.tasks.Input;
import org.gradle.process.CommandLineArgumentProvider;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class SystemPropertyCommandLineArgumentProvider implements CommandLineArgumentProvider {
private final Map<String, Object> systemProperties = new LinkedHashMap<>();
public void systemProperty(String key, Object value) {
systemProperties.put(key, value);
}
@Override
public Iterable<String> asArguments() {
return systemProperties.entrySet()
.stream()
.map(entry -> "-D" + entry.getKey() + "=" + entry.getValue())
.collect(Collectors.toList());
}
// Track system property keys as an input so our build cache key will change if we add properties but values are still ignored
@Input
public Iterable<String> getPropertyNames() {
return systemProperties.keySet();
}
}

View File

@ -22,7 +22,9 @@ import com.avast.gradle.dockercompose.ComposeExtension;
import com.avast.gradle.dockercompose.DockerComposePlugin;
import com.avast.gradle.dockercompose.tasks.ComposeUp;
import org.elasticsearch.gradle.OS;
import org.elasticsearch.gradle.SystemPropertyCommandLineArgumentProvider;
import org.elasticsearch.gradle.precommit.TestingConventionsTasks;
import org.gradle.api.Action;
import org.gradle.api.DefaultTask;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
@ -142,7 +144,8 @@ public class TestFixturesPlugin implements Plugin<Project> {
configureServiceInfoForTask(
task,
fixtureProject,
task::systemProperty
(name, host) ->
task.getExtensions().getByType(SystemPropertyCommandLineArgumentProvider.class).systemProperty(name, host)
);
task.dependsOn(fixtureProject.getTasks().getByName("postProcessFixture"));
})
@ -165,28 +168,32 @@ public class TestFixturesPlugin implements Plugin<Project> {
private void configureServiceInfoForTask(Task task, Project fixtureProject, BiConsumer<String, Integer> consumer) {
// Configure ports for the tests as system properties.
// We only know these at execution time so we need to do it in doFirst
task.doFirst(theTask ->
fixtureProject.getExtensions().getByType(ComposeExtension.class).getServicesInfos()
.forEach((service, infos) -> {
infos.getTcpPorts()
.forEach((container, host) -> {
String name = "test.fixtures." + service + ".tcp." + container;
theTask.getLogger().info("port mapping property: {}={}", name, host);
consumer.accept(
name,
host
);
});
infos.getUdpPorts()
.forEach((container, host) -> {
String name = "test.fixtures." + service + ".udp." + container;
theTask.getLogger().info("port mapping property: {}={}", name, host);
consumer.accept(
name,
host
);
});
})
task.doFirst(new Action<Task>() {
@Override
public void execute(Task theTask) {
fixtureProject.getExtensions().getByType(ComposeExtension.class).getServicesInfos()
.forEach((service, infos) -> {
infos.getTcpPorts()
.forEach((container, host) -> {
String name = "test.fixtures." + service + ".tcp." + container;
theTask.getLogger().info("port mapping property: {}={}", name, host);
consumer.accept(
name,
host
);
});
infos.getUdpPorts()
.forEach((container, host) -> {
String name = "test.fixtures." + service + ".udp." + container;
theTask.getLogger().info("port mapping property: {}={}", name, host);
consumer.accept(
name,
host
);
});
});
}
}
);
}