TM-41 Ability to resume test runs (#5573)

* TM-41 writing test completions to file to keep track of what was finished. to be used in the case that a pod terminates abruptly

* TM-41 addressing PR comments

* TM-41 addressing PR comments

* TM-41 adding exclusion list to guard against tests being passes as a group

* TM-41 trying to find the jenkins breakpoint

* TM-41 debugging jenkins

* TM-41 revert debugging change

* TM-41 revert debugging changes

* TM-41 revert debugging changes

* TM-41 fixing merge conflicts

* TM-41 now that TM-40 is merged static needs to be updated

* TM-41 refactor constant

* TM-41 fixing jenkins failure

* TM-41 trying new path

* TM-41 moving the file reading to the task that will be executed by the workers as the master does not have a persistent volume

* TM-41 moving the after test as well
This commit is contained in:
Razvan Codreanu 2019-10-15 15:14:41 +01:00 committed by Dominic Fox
parent a1dd6abe17
commit 45172515ac
2 changed files with 25 additions and 3 deletions

View File

@ -10,7 +10,6 @@ import org.gradle.api.tasks.testing.Test
*/
class DistributedTesting implements Plugin<Project> {
static def getPropertyAsInt(Project proj, String property, Integer defaultValue) {
return proj.hasProperty(property) ? Integer.parseInt(proj.property(property).toString()) : defaultValue
}
@ -33,6 +32,7 @@ class DistributedTesting implements Plugin<Project> {
//1. add the task to determine all tests within the module
//2. modify the underlying testing task to use the output of the listing task to include a subset of tests for each fork
//3. KubesTest will invoke these test tasks in a parallel fashion on a remote k8s cluster
//4. after each completed test write its name to a file to keep track of what finished for restart purposes
project.subprojects { Project subProject ->
subProject.tasks.withType(Test) { Test task ->
println "Evaluating ${task.getPath()}"
@ -47,7 +47,6 @@ class DistributedTesting implements Plugin<Project> {
if (!task.hasProperty("ignoreForDistribution")) {
KubesTest parallelTestTask = generateParallelTestingTask(subProject, task, imageBuildingTask, providedTag)
}
}
}
@ -129,6 +128,20 @@ class DistributedTesting implements Plugin<Project> {
maxHeapSize = "6g"
doFirst {
filter {
List<String> executedTests = []
File executedTestsFile = new File(KubesTest.TEST_RUN_DIR + "/executedTests.txt")
try {
executedTests = executedTestsFile.readLines()
} catch (FileNotFoundException e) {
executedTestsFile.createNewFile()
}
task.afterTest { desc, result ->
executedTestsFile.withWriterAppend { writer ->
writer.writeLine(desc.getClassName() + "." + desc.getName())
}
}
def fork = getPropertyAsInt(subProject, "dockerFork", 0)
subProject.logger.info("requesting tests to include in testing task ${task.getPath()} (idx: ${fork})")
List<String> includes = globalAllocator.getTestIncludesForForkAndTestTask(
@ -141,10 +154,18 @@ class DistributedTesting implements Plugin<Project> {
excludeTestsMatching "*"
}
includes.removeAll(executedTests)
executedTests.forEach { exclude ->
subProject.logger.info "excluding: $exclude for testing task ${task.getPath()}"
excludeTestsMatching exclude
}
includes.forEach { include ->
subProject.logger.info "including: $include for testing task ${task.getPath()}"
includeTestsMatching include
}
failOnNoMatchingTests false
}
}

View File

@ -22,6 +22,7 @@ import java.util.stream.IntStream;
public class KubesTest extends DefaultTask {
static final String TEST_RUN_DIR = "/test-runs";
private static final ExecutorService executorService = Executors.newCachedThreadPool();
/**
* Name of the k8s Secret object that holds the credentials to access the docker image registry
@ -247,7 +248,7 @@ public class KubesTest extends DefaultTask {
.addToRequests("memory", new Quantity(memoryGbPerFork.toString() + "Gi"))
.endResources()
.addNewVolumeMount().withName("gradlecache").withMountPath("/tmp/gradle").endVolumeMount()
.addNewVolumeMount().withName("testruns").withMountPath("/test-runs").endVolumeMount()
.addNewVolumeMount().withName("testruns").withMountPath(TEST_RUN_DIR).endVolumeMount()
.endContainer()
.addNewImagePullSecret(REGISTRY_CREDENTIALS_SECRET_NAME)