Skip to content

Commit

Permalink
For docker runs (tests) ensure we get results even when the run (test…
Browse files Browse the repository at this point in the history
…) fails. (#4254)

* Ensure the buildAndRun task runs the sync task even if it fails.

* Followup to review comment.

* Recover previous fix.

* Followup to review comments.
  • Loading branch information
jcferretti authored Aug 2, 2023
1 parent bb37659 commit 51b88b3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
26 changes: 13 additions & 13 deletions buildSrc/src/main/groovy/Docker.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,19 @@ class Docker {
// Single task with explicit inputs and outputs, to let gradle detect if it is up to date, and let docker
// cache what it can.

// Sync outputs to the desired location
def syncAfterBuildAndRun = project.tasks.register("${taskName}Sync", Sync) { sync ->
sync.with {
// run the provided closure first
cfg.copyOut.execute(sync)

// then set the from location
from dockerCopyLocation
}
}

// Note that if "showLogsOnSuccess" is true, we don't run this way, since that would omit logs when cached.
def buildAndRun = project.tasks.register("${taskName}Run", CombinedDockerRunTask) { cacheableDockerTask ->
return project.tasks.register(taskName, CombinedDockerRunTask) { cacheableDockerTask ->
cacheableDockerTask.with {
// mark inputs, depend on dockerfile task and input sync task
inputs.files(makeImage.get().outputs.files)
Expand Down Expand Up @@ -334,18 +345,7 @@ class Docker {

remotePath.set(cfg.containerOutPath)
outputDir.set(project.file(dockerCopyLocation))
}
}
// Sync outputs to the desired location
return project.tasks.register(taskName, Sync) { sync ->
sync.with {
dependsOn buildAndRun

// run the provided closure first
cfg.copyOut.execute(sync)

// then set the from location
from dockerCopyLocation
finalizedBy syncAfterBuildAndRun
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class CombinedDockerRunTask extends AbstractDockerRemoteApiTask {
throw new GradleException("${failedMessage}, check logs for details")
}
}

} finally {
if (containerId == null) {
return;
Expand Down
2 changes: 1 addition & 1 deletion cpp-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,5 @@ def testCppClient = Docker.registerDockerTask(project, 'testCppClient') {
parentContainers = [ Docker.registryTask(project, 'cpp-client-base') ]
entrypoint = ['/cpp-client/install/bin/cpp-tests-to-junit.sh', '/out/cpp-test.xml', '/out/cpp-test.log']
}
deephavenDocker.shouldLogIfTaskFails tasks.named('testCppClientRun')
deephavenDocker.shouldLogIfTaskFails testCppClient
tasks.check.dependsOn(testCppClient)
2 changes: 1 addition & 1 deletion go/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,5 @@ def testGoClient = Docker.registerDockerTask(project, 'testGoClient') {
parentContainers = [ Docker.registryTask(project, 'go') ]
entrypoint = ['./go-test-to-junit.sh', '/out/go-test.xml', '/out/go.log']
}
deephavenDocker.shouldLogIfTaskFails tasks.named('testGoClientRun')
deephavenDocker.shouldLogIfTaskFails testGoClient
tasks.check.dependsOn(testGoClient)
8 changes: 5 additions & 3 deletions py/client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ deephavenDocker {
networkName.set "pydeephaven-network-${randomSuffix}"
}

tasks.getByName('check').dependsOn(Docker.registerDockerTask(project, 'testPyClient') {
def testPyClient = Docker.registerDockerTask(project, 'testPyClient') {
copyIn {
from('pydeephaven') {
into 'project/pydeephaven'
Expand Down Expand Up @@ -112,5 +112,7 @@ tasks.getByName('check').dependsOn(Docker.registerDockerTask(project, 'testPyCli
copyOut {
into layout.buildDirectory.dir('test-results')
}
})
deephavenDocker.shouldLogIfTaskFails tasks.named('testPyClientRun')
}

tasks.getByName('check').dependsOn(testPyClient)
deephavenDocker.shouldLogIfTaskFails testPyClient

0 comments on commit 51b88b3

Please sign in to comment.