Repository navigation
Conversation
The Docker daemon of some GitHub-hosted runners, so far all in the Azure region westus3, gets no answer from IBM's registry, icr.io, where the Db2 image comes from: every pull fails within about 15 seconds with Docker's 500 for "Get https://icr.io/v2/", "request canceled while waiting for connection" or "context deadline exceeded". Since the Db2 rows landed in #16750, that has failed six Hibernate7 Functional Tests jobs and two Coverage jobs, each after about 20 minutes: Testcontainers retries the pull for two minutes, GenericContainer.doStart() retries it in full once more while it builds its error message, and each of the four specs with a Db2 row starts over. The specs now start the container of a row through DatabaseContainers.start(). For Db2 it fetches the image once per test JVM before it starts the container, and when the fetch fails it throws TestAbortedException, so the Db2 rows are reported as skipped with the reason, as they are on arm64. The other Hibernate 7 jobs of the run still run them. A container that fails to start once its image is there still fails its row.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 8.0.x #16929 +/- ##
==================================================
+ Coverage 62.3608% 62.5751% +0.2142%
- Complexity 27305 27545 +240
==================================================
Files 2248 2249 +1
Lines 111469 111725 +256
Branches 20422 20486 +64
==================================================
+ Hits 69513 69912 +399
+ Misses 32622 32454 -168
- Partials 9334 9359 +25 🚀 New features to boost your workflow:
|
jamesfredley
left a comment
There was a problem hiding this comment.
Not approving. One failed image fetch skips every later row in that process, even after the image can be fetched.
| } | ||
|
|
||
| private static synchronized void fetchDb2Image() { | ||
| if (db2FetchFailure == null) { |
There was a problem hiding this comment.
The first row cannot fetch the image, then the registry recovers before the next row. The next row is skipped without trying again. A row that can fetch the image should run. Try the fetch again after a failure.
There was a problem hiding this comment.
Each failed job so far already did what this asks: every Db2 row retried for about 2.5 minutes on its own, so each job retried for about 20 minutes, and none of the 28 rows in the 7 failed jobs I checked got the image (all 16 attempts in the build scan failed too). A short registry outage is already covered by the retries inside the first fetch. A later retry would add about 7.5 minutes to each such job and has not recovered once so far. A skipped row shows in the report with its reason, and the other Hibernate 7 jobs of the run still run the Db2 rows. If we ever see a runner recover, retrying is a small change.
|
Doesn't this have the potential to mask failures? Since they'll always be skipped? There's no indication on a PR when a test is skipped this way. |
A Db2 row skipped because the image could not be fetched showed only in the test report, so neither the job nor its pull request showed that the Db2 rows had not run there. On GitHub Actions, a test task of grails-data-hibernate7-core that skipped Db2 rows for that reason now ends with a warning workflow command, which adds an annotation with the number of rows and the reason to the job.
|
They are skipped only on a runner whose Docker daemon cannot fetch the image from icr.io. Everything after the fetch fails as before: a Db2 container that does not start, or a Db2 row whose assertions fail. On this PR's own CI, the Db2 rows ran and passed in all four jobs that run them. Those four jobs are the three Hibernate7 Functional Tests jobs that run You're right that the PR showed nothing when the rows were skipped. The new commit adds a warning: on GitHub Actions, a test task of
With the image pointed at an unreachable registry, the build passed with the 4 Db2 rows of this branch skipped and printed that warning once, also when the configuration cache entry was reused. With the real image, every row ran and there was no warning. |
codeconsole
left a comment
There was a problem hiding this comment.
Two issues need fixing before merge, plus unit test coverage for the new skip behavior:
- Build-cache poisoning suppresses
Db2SkipWarningand skips Db2 on healthy runners:gradle/hibernate7-test-config.gradleandgradle/grails-data-tck-config.gradlekeepoutputs.cacheIf { cacheTests }enabled even in CI (unlikegradle/test-config.gradle's!ciBuild && cacheTests), andorg.gradle.caching=trueis enabled repo-wide. Previously a failed Db2 fetch failed the task and was never cached; now the task passes with Db2 skipped and its output can be stored in the local/remote Develocity build cache. Any later run without--rerun-tasks(such asCoverage - grails-core, which runsjacocoAggregateReportwithout--rerun-tasks, or a local rerun) can restore:grails-data-hibernate7-core:testFROM-CACHEwithout running Db2 and without firingDb2SkipWarning. - Local failures are silently masked:
fetchDb2Image()skips on anyContainerFetchExceptioneven outside GitHub Actions, whereDb2SkipWarningis not attached. Gate the skip fallback onGITHUB_ACTIONS == 'true'so local runs fail loudly. - Missing automated tests: Neither
DatabaseContainers.start()nor theREASONprefix contract /Db2SkipWarningis covered by automated tests, andDb2SkipWarningnever runs on healthy CI runners.
| } | ||
|
|
||
| if (providers.environmentVariable('GITHUB_ACTIONS').orNull == 'true') { | ||
| tasks.withType(Test).configureEach { Test task -> |
There was a problem hiding this comment.
Because hibernate7-test-config.gradle and grails-data-tck-config.gradle set outputs.cacheIf { cacheTests } (which stays true in CI, unlike test-config.gradle's !ciBuild && cacheTests), a :grails-data-hibernate7-core:test run that passes with the 4 Db2 rows skipped can be stored in the local or remote Develocity build cache (--rerun-tasks in hibernate7Functional skips cache lookup, not cache store). A subsequent run without --rerun-tasks — such as Coverage - grails-core (.github/workflows/coverage.yml) — then restores the task FROM-CACHE, keeping Db2 skipped on a healthy runner and never invoking Db2SkipWarning.
Disable build caching for this module's Test tasks (e.g. task.outputs.cacheIf('Db2 rows may be skipped when icr.io is unreachable') { false }, and/or disable test caching in CI in hibernate7-test-config.gradle and grails-data-tck-config.gradle to match test-config.gradle).
There was a problem hiding this comment.
This no longer applies since f061141: the Db2 rows fail instead of being skipped, so a failed fetch fails the task again, and nothing is stored. For the record, Coverage does load this task from the cache (:grails-data-hibernate7-core:test FROM-CACHE in both of the last two Coverage runs on 8.0.x, 45115506146 and 45080688129). But the Hibernate 7 shard jobs, which run the Db2 rows, use testShard --rerun-tasks and load no test results, so a cached skip couldn't have made a healthy runner skip them there.
| try { | ||
| // Pulls the image unless Docker has it; the container keeps the name, so start() does not pull again | ||
| DB2.dockerImageName | ||
| } catch (ContainerFetchException e) { |
There was a problem hiding this comment.
fetchDb2Image() catches ContainerFetchException unconditionally, even outside GitHub Actions where Db2SkipWarning is not attached. On a local machine, a typoed/retired Db2 image tag or registry/daemon error will silently skip all 4 Db2 rows and finish with BUILD SUCCESSFUL (and UP-TO-DATE on the next run).
Gate the skip-on-fetch-failure fallback on System.getenv('GITHUB_ACTIONS') == 'true' (matching grails-data-hibernate7/core/build.gradle) so local runs fail loudly, and add a unit spec covering DatabaseContainers.start() (null/running no-ops, non-Db2 passthrough, Db2 fetch-once abort caching, and post-fetch start() failures still failing).
There was a problem hiding this comment.
Agreed, and it went further than local runs. A registry that answers fails the pull within a second with a NotFoundException (Status 404: … not found, for a missing tag and for a missing repository alike). Every runner gets that answer, so a typo or a retired tag would have skipped the Db2 rows in every job, and only the warnings would have shown it. Since f061141 nothing is skipped: the first Db2 row fails with the fetch failure, and every later one fails with it at once.
DatabaseContainersSpec covers start() for no container, a running one, a container other than Db2, which is started without a fetch, and one that fails to start. It also covers the fetch: once when it succeeds, once when it fails, with every later row failing with the same failure, and the message for a timeout, a 404 and a failure without a cause.
With the four specs that have Db2 rows:
- With a tag that isn't there, the four Db2 rows fail within 2 s each with
Pulling icr.io/db2_community/db2:0.0.0-nope failed: Status 404: … not found. - With a registry that can't be resolved,
db2.invalid, the first Db2 row fails after 206 s withPulling db2.invalid/db2_community/db2:11.5.9.0 failed: Condition with Lambda expression in org.testcontainers.images.RemoteDockerImage was not fulfilled within 2 minutes., and the other three fail with it within 2 s each.
With the real image, all tests of grails-data-hibernate7-core pass: 4,615 tests, with the 15 skipped as before.
| // On GitHub Actions, the build script of this module looks for the start of this message to warn about the | ||
| // skipped rows | ||
| throw new TestAbortedException( | ||
| "The Db2 image could not be fetched, so the Db2 rows are skipped: ${db2FetchFailure.message}", |
There was a problem hiding this comment.
Optional clarity improvement: db2FetchFailure.message is only Testcontainers' wrapper (Can't get Docker image: RemoteDockerImage(...)). Including db2FetchFailure.cause?.message when present would make the GitHub Actions warning annotation show the failure reason directly without opening the build scan.
There was a problem hiding this comment.
Done in f061141. The message names the image and the cause, for example Pulling icr.io/db2_community/db2:11.5.9.0 failed: Condition with Lambda expression in org.testcontainers.images.RemoteDockerImage was not fulfilled within 2 minutes. On westus3 the cause is that timeout: the Docker daemon's 500 for each attempt is only in Testcontainers' log of its retries, which the build scan keeps.
|
@matrei a heads-up on sequencing, nothing to change here. #16954, #16955 and #16962 also edit The two do different jobs. This PR skips the Db2 rows when the registry cannot be reached; mine skip rows when the machine cannot run them. Yours was opened first, so I will not touch |
…not be fetched A skip needed a guard for every way it could hide a real failure. A tag that is not there fails the pull with a 404 on every runner, so it skipped the rows everywhere. A local run skipped them without a word. The warning on GitHub Actions depended on the start of the skip message. And a test result with the rows skipped could be stored in the build cache. The rows now fail again. The image is still fetched once per test JVM, and once that has failed, every later Db2 row fails with that failure at once. A job on a runner that cannot reach icr.io now fails after one round of attempts instead of after about 20 minutes. The message names the image and the cause of the failure. The warning listener and the opentest4j dependency are no longer needed, so the build script is as on 8.0.x.
|
@codeconsole thanks for the review. It made me drop the skip. Making a skip safe needed a guard for each way it could hide a real failure: a tag that isn't there skipped the rows on every runner, a local run skipped them without a word, the warning depended on a message prefix, and a cached result could carry the skip. That's more than a workaround for one region's network is worth. Since f061141, the Db2 rows fail again, but after one round of attempts, about 3.5 minutes, instead of about 20, and with a message that says what went wrong. A rerun of the job usually lands in another region and passes. The warning listener and the opentest4j dependency are gone, so @jdaugherty that also answers your question whether the skip could hide failures: nothing is skipped now. @jamesfredley one failed fetch still fails the later Db2 rows of the test JVM at once. In the 7 failed jobs whose logs I checked in November, all four Db2 rows failed, each after its own round of attempts, so a later fetch wouldn't have got through either. Since 11-12, 11 more jobs have failed on the fetch, all of them in westus3. I've updated the title and the description. |
codeconsole
left a comment
There was a problem hiding this comment.
Two issues should be fixed before merging:
DatabaseContainersSpecnever exercises theif (container.is(DB2))wiring inDatabaseContainers.start()—deleting lines 88–90 or callingcontainer.start()beforefetch()still leaves all tests green.ImageFetch.fetch()setsattempted = truebefore callingcontainer.dockerImageName, so an uncaughtError(whichGenericContainer.getDockerImageName()does not wrap inContainerFetchException) leavesattempted == truewithfailure == nulland makes later calls treat the fetch as succeeded.
See inline comments for details and two minor clarity suggestions.
| if (container == null || container.running) { | ||
| return | ||
| } | ||
| if (container.is(DB2)) { |
There was a problem hiding this comment.
DatabaseContainersSpec never exercises this branch: it calls DatabaseContainers.start() only with null and non-Db2 mocks, and tests ImageFetch.fetch() in isolation. Deleting lines 88–90 or moving them after container.start() leaves every test passing.
Delegate start(GenericContainer) to a package-private helper (e.g., start(GenericContainer container, GenericContainer db2, ImageFetch db2ImageFetch)) and add tests in DatabaseContainersSpec proving that for Db2 fetch() runs before container.start(), container.start() is skipped when fetch() fails, and a subsequent start() after a ContainerLaunchException does not re-fetch.
There was a problem hiding this comment.
Right, the spec only reached ImageFetch directly. start(GenericContainer) now hands the Db2 container and the fetch of its image to a package-scope start(container, db2, db2ImageFetch), and three new features go through it with a mock Db2 container:
- its image is fetched before it is started,
- it is not started when the fetch fails, by that row or the next,
- after a
ContainerLaunchException, the next row starts it again without fetching again.
The feature for a container other than Db2 now also checks that the Db2 fetch is not touched. With the Db2 branch deleted, or moved after container.start(), all three new features fail.
| */ | ||
| synchronized void fetch() { | ||
| if (!attempted) { | ||
| attempted = true |
There was a problem hiding this comment.
Setting attempted = true before container.dockerImageName runs leaves ImageFetch claiming success (attempted == true, failure == null) if a non-ContainerFetchException throwable (such as an Error, which GenericContainer.getDockerImageName() does not catch) escapes. Move attempted = true after the try/catch block so it is only set once the fetch either succeeds or records a ContainerFetchException.
There was a problem hiding this comment.
Moved: attempted is set after the try/catch, so an error that ends the fetch leaves it unset and the next row fetches the image again. A new feature throws a NoClassDefFoundError from the first fetch and checks that the second one fetches; it fails with attempted set first.
The later rows wouldn't have passed as fetched without the move, though. container.start() resolves the image again, because Testcontainers' LazyFuture keeps no value from a resolve that threw, so each of them would have pulled once more, as before this PR.
| attempted = true | ||
| try { | ||
| // Pulls the image unless Docker has it; the container keeps the name, so start() does not pull again | ||
| container.dockerImageName |
There was a problem hiding this comment.
(Optional) container.getDockerImageName() reads more clearly than bare property access container.dockerImageName when the call is made solely for its side effect.
There was a problem hiding this comment.
I'd keep the property: the Groovy in this module reads getters as properties, and the comment above the line says it's read for the pull.
| import org.testcontainers.containers.ContainerFetchException | ||
| import org.testcontainers.containers.ContainerLaunchException | ||
| import org.testcontainers.containers.GenericContainer | ||
| import org.testcontainers.shaded.org.awaitility.core.ConditionTimeoutException |
There was a problem hiding this comment.
(Optional) ImageFetch.fetch() only reads failure.cause?.message ?: failure.message and does not branch on the cause type. Importing Testcontainers' internal shaded ConditionTimeoutException (and transitive docker-java NotFoundException) couples this test to Testcontainers' shading layout while timeout() and notFound() exercise the same branch. Using plain new RuntimeException('...') avoids those imports, and adding a new RuntimeException() case (non-null cause with null message) covers the ?: fallback branch too.
There was a problem hiding this comment.
Added the row for a cause without a message. I'd keep the two exception types, though. They are what Testcontainers and the Docker daemon throw for the two failures we've seen, a registry that doesn't answer and a tag that isn't there, and the 404 row shows the Status 404: that docker-java puts before the message, as the Db2 rows show it. If Testcontainers stops shading Awaitility, the spec stops compiling, so it can't go stale unnoticed.
DatabaseContainersSpec called start() only with containers other than Db2, so it still passed with the Db2 fetch removed from start() or moved after container.start(). start() now hands the Db2 container and the fetch of its image to a package-scope overload, which the spec calls with a mock Db2 container. ImageFetch marked the fetch as tried before it ran, so an error that ended it, which getDockerImageName() does not wrap, left the image looking fetched. It is now marked once the fetch has succeeded or failed with a ContainerFetchException.
✅ All tests passed ✅🏷️ Commit: e94f572 Learn more about TestLens at testlens.app/docs. |
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. A missing database image still fails the suite.
| } | ||
| if (failure != null) { | ||
| // The message of the exception only names the image; its cause says what went wrong | ||
| throw new ContainerFetchException( |
There was a problem hiding this comment.
A row that needs a database image runs when that image cannot be fetched. The suite fails, because the failed fetch is thrown instead of skipping that row. Skip the row.
There was a problem hiding this comment.
That's on purpose: a missing image has to fail the suite. The first version of this PR skipped the row, and codeconsole's review showed what that hides. A tag that isn't there gets a 404 on every runner, so a typo or a retired tag would have skipped the Db2 rows in every job, and a local run would have skipped them without a word. Since f061141 the rows fail instead, but after one round of attempts, about 3.5 minutes instead of about 20, and with a message that names the image and the cause. On a westus3 runner, a rerun of the job usually lands in another region and passes.
codeconsole
left a comment
There was a problem hiding this comment.
No blocking issues found; two optional visibility tweaks noted inline.
| static final OracleContainer ORACLE = new OracleContainer('gvenzl/oracle-free:slim-faststart') | ||
| .withStartupTimeout(Duration.ofMinutes(3)) | ||
|
|
||
| static final String DB2_IMAGE = 'icr.io/db2_community/db2:11.5.9.0' |
There was a problem hiding this comment.
(Optional) DB2_IMAGE is only used inside DatabaseContainers, so this can be private static final.
| * once instead of fetching it again. | ||
| */ | ||
| @CompileStatic | ||
| static final class ImageFetch { |
There was a problem hiding this comment.
(Optional) ImageFetch is only referenced within grails.gorm.tests; marking it @PackageScope matches the package-private start overload.
Description
Since the Db2 rows of the Hibernate 7 specs landed in #16750, Hibernate7 Functional Tests and Coverage jobs have failed on them with
All of them ran on runners in the Azure region westus3, which the header of the job log names. By 11-11, 8 of the 19 jobs that ran there had failed this way, and none of the 36 in other regions. From 11-12 to 11-23, 11 more jobs failed on the fetch, all in westus3. The test output in the build scan shows that the runner's Docker daemon gets no answer from IBM's registry at all. Every attempt fails within about 15 seconds with
or with
context deadline exceeded. A longer pull timeout, or pulling the image before the tests, would not get it either.Such a job lost about 20 minutes before it failed:
GenericContainer.doStart()retries it in full once more while it builds its error message.The specs now start the container of a row through
DatabaseContainers.start(). For Db2, it fetches the image once per test JVM before it starts the container. When the fetch fails, the first Db2 row fails with the failure and every later one fails with it at once. A job on such a runner then fails after one round of attempts, about 3.5 minutes, instead of about 20, and the message names the image and what went wrong:A rerun of the job usually lands in another region and passes. A registry that answers, for example that the tag is not there, fails the rows the same way, within a second. A container that fails to start once its image is there still fails its row.
DatabaseContainers.start()replaces the start block that the seven specs using the shared containers each repeated. For the three specs without a Db2 row, nothing changes.The first version of this pull request skipped the Db2 rows instead. Review showed that a skip needs a guard for each way it could hide a real failure, for example a tag that isn't there, which every runner would have skipped as well, so the rows fail now.
Verification
DatabaseContainersSpeccoversstart()for no container, a running one, a container other than Db2 and one that fails to start. For the Db2 container, it covers that the image is fetched before the container is started, that the container is not started when the fetch fails, and that after a failed start the next row starts it again without fetching again. It covers the fetch too: once when it succeeds, once when it fails, with every later row failing with the same failure, again after an error ended it, and the message for a timeout, a 404, a failure without a cause and a cause without a message.Pulling icr.io/db2_community/db2:0.0.0-nope failed: Status 404: … not found.db2.invalid, the first Db2 row fails after 206 s withPulling db2.invalid/db2_community/db2:11.5.9.0 failed: Condition … was not fulfilled within 2 minutes., and the other three fail with it within 2 s each.grails-data-hibernate7-corepass with the real image: 4,620 tests, with the 15 skipped as before.Merging
It merges up cleanly to 8.1.x, 9.0.x, 9.1.x and 10.0.x.