Skip to content

Commit

Permalink
Add explicit build flag for experimenting with test execution cacheab…
Browse files Browse the repository at this point in the history
…ility (#42649)

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

* Fix checkstyle violations
  • Loading branch information
mark-vieira authored and alpar-t committed Sep 23, 2019
1 parent 7bc86f2 commit ef0b757
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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,
Expand All @@ -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())

Expand Down Expand Up @@ -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()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
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;
Expand Down Expand Up @@ -142,7 +144,8 @@ public void apply(Project project) {
configureServiceInfoForTask(
task,
fixtureProject,
task::systemProperty
(name, host) ->
task.getExtensions().getByType(SystemPropertyCommandLineArgumentProvider.class).systemProperty(name, host)
);
task.dependsOn(fixtureProject.getTasks().getByName("postProcessFixture"));
})
Expand All @@ -165,28 +168,32 @@ private void conditionTaskByType(TaskContainer tasks, TestFixtureExtension exten
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
);
});
});
}
}
);
}

Expand Down

0 comments on commit ef0b757

Please sign in to comment.