-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Server logs should be written when integration tests fail #4804
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -300,7 +300,34 @@ class Docker { | |
|
||
if (cfg.copyOut && !cfg.showLogsOnSuccess) { | ||
// Single task with explicit inputs and outputs, to let gradle detect if it is up to date, and let docker | ||
// cache what it can. | ||
// cache what it can. While far more efficient for gradle to run (or rather, know when it does not need to | ||
// run), it is also more bug-prone while we try to get various competing features working. | ||
// | ||
// To handle these use cases, we're not using dependsOn as we typically would do, but instead using | ||
// finalizedBy and onlyIf. Here's a mermaid diagram: | ||
// | ||
// graph LR; | ||
// MakeImage -. finalizedBy .-> Run | ||
// Sync -- dependsOn --> MakeImage | ||
// Run -. finalizedBy .-> Sync | ||
// | ||
// | ||
// Unlike "A dependsOn B", "B finalized A" will let B run if A failed, and will not run A if B must run. | ||
// Combining the chain of finalizedBys between MakeImage <- Run <- Sync with the dependsOn from | ||
// Sync -> MakeImage lets us handle the following cases: | ||
// * Successful run, output is sync'd afterwards, final task succeeds | ||
// * Failed run, output is sync'd afterwards, final task fails | ||
// * Failed image creation, no run, no sync, no final task | ||
// * Previously successful run with no source changes, no tasks run (all "UP-TO-DATE") | ||
// | ||
// Tests to run to confirm functionality: | ||
// * After changes, confirm that :web:assemble runs (isn't all "UP-TO-DATE") | ||
// * Then run again with no changes, confirm all are UP-TO-DATE, roughly 2s build time | ||
// * Edit a test that uses deephavenDocker to fail, confirm that the test fails, that the test-reports | ||
// are copied out, and that server logs are written to console | ||
// * Ensure that if the test is set to pass that the test-reports are copied out, and server logs are | ||
// not written. | ||
// Note that at this time integration tests using the deephavenDocker plugin are never UP-TO-DATE. | ||
|
||
// 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 -> | ||
|
@@ -337,35 +364,34 @@ class Docker { | |
} | ||
} | ||
|
||
// Handle copying failure. This is now distinct from the "actual" Sync task that depends directly | ||
// on the CombinedDockerRunTask. | ||
def syncAfterFail = project.tasks.register("${taskName}SyncAfterFail", Sync) { sync -> | ||
// Specify that makeImage is finalized by buildAndRun - that is, in this configuration buildAndRun | ||
// must run after makeImage finishes | ||
makeImage.configure {it -> | ||
it.finalizedBy(buildAndRun) | ||
} | ||
|
||
// Handle copying output from the docker task to the user-controlled location | ||
def syncOutput = project.tasks.register(taskName, Sync) { sync -> | ||
sync.with { | ||
dependsOn(makeImage) | ||
// run the provided closure first | ||
cfg.copyOut.execute(sync) | ||
|
||
// then set the from location | ||
from dockerCopyLocation | ||
|
||
onlyIf { buildAndRun.get().state.failure != null } | ||
doLast { | ||
if (buildAndRun.get().state.failure != null) { | ||
throw new GradleException('Docker task failed, see earlier task failures for details') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might add a comment this isn't an illegal state, we just want to preserve / propagate the failure, correct? I wonder if we should have a separate task that propagates this failure, instead of attaching it to the Sync task? (which may have specific semantics attached to sync-related failures.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct - not an illegal state (and the choice of GradleException is I thought intended to convey that), but just a failure. If this task did not throw an exception (or otherwise fail), it wouldn't be clear to other tasks that they should/shouldn't continue (e.g. "if it failed, dont continue to build downstream artifacts" vs "if it failed, make sure we dump the server's logs"). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note also that a new task with actions (i.e. "fail if that other thing failed") but no inputs or outputs can never be up to date. I'm not aware of Sync specific errors, but can add a comment here to call out what is going on, besides the wall of text written at the top of this section. |
||
} | ||
} | ||
} | ||
} | ||
buildAndRun.configure {t -> | ||
t.finalizedBy syncAfterFail | ||
t.finalizedBy syncOutput | ||
} | ||
|
||
// 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 | ||
} | ||
} | ||
return syncOutput | ||
} | ||
// With no outputs, we can use the standard individual containers, and gradle will have to re-run each time | ||
// the task is invoked, can never be marked as up to date. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your comment
buildAndRun must run after makeImage
is a bit at odds with the typical gradle terminology. I'm digging in now; I don't know if finalizedBy is the technically correct solution here (it may very well be...).https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:finalizer_tasks
https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:ordering_tasks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mustRunAfter
/shouldRunAfter
only sets an ordering requirement, but does not mandate that the earlier or later task run at all, they can run or not run independently.On the other hand,
b.dependsOn(a)
means that ifb
is requested to run,a
must run first and must be successful, whereasa.finalizedBy(b)
means that ifa
will run,b
must run afterwards (regardless of whether or nota
is successful).