Repository navigation
test: fix flaky KubernetesTaskRunnerTest start tests - #20316
Conversation
KubernetesTaskRunner.start() schedules the cleanup of completed peon jobs on a background executor with a 1 ms initial delay. Whether that first cleanup runs before the test's verifyAll() depends on thread scheduling, so the strict mock intermittently reports an unexpected deleteCompletedPeonJobsOlderThan() call. Expect the cleanup call any number of times in the tests that start a runner, and stop every locally created runner so the executor does not outlive the test.
There was a problem hiding this comment.
🟢 Approval recommended
The changes are narrowly scoped to tests and deterministically address the known race without weakening unrelated mock verification.
Pull request overview
This PR fixes intermittent flakiness in KubernetesTaskRunnerTest caused by KubernetesTaskRunner.start() scheduling background cleanup work that can race with strict EasyMock verification.
Changes:
- Added a small test helper to allow
peonClient.deleteCompletedPeonJobsOlderThan(..., MILLISECONDS)to be invoked any number of times duringstart(). - Wrapped the three tests that construct and
start()a local runner intry/finallyto ensurerunner.stop()is always called and background executors don’t outlive the test.
File summaries
| File | Description |
|---|---|
| extensions-core/kubernetes-overlord-extensions/src/test/java/org/apache/druid/k8s/overlord/KubernetesTaskRunnerTest.java | Makes start()-related tests deterministic by relaxing only the scheduled cleanup call and ensuring locally created runners are stopped reliably. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
The The failing test is This is the flake tracked in #20312 (item 7) and fixed by #20320: |
FrankChen021
left a comment
There was a problem hiding this comment.
🟢 Approval recommended
No actionable issues found in this review. The only changed file is extensions-core/kubernetes-overlord-extensions/src/test/java/org/apache/druid/k8s/overlord/KubernetesTaskRunnerTest.java; I inspected it in full along with the KubernetesTaskRunner.start()/stop() implementation and the relevant test fixture setup. The new expectation is limited to the scheduled cleanup call, while the existing start expectations remain strict, and each locally created runner that is started is stopped in finally.
Changed file reviewed: extensions-core/kubernetes-overlord-extensions/src/test/java/org/apache/druid/k8s/overlord/KubernetesTaskRunnerTest.java.
Reviewed 1 of 1 changed files.
Validation: git diff --check passed for the prepared PR-head diff. No builds or tests were run, per the requested static-only scope.
This is an automated review by Codex GPT-5.6-Luna(max)
Related to #20312 (item 1).
Description
KubernetesTaskRunnerTest.test_start_whenDeserializationExceptionThrown_isIgnoredfails intermittently on master with:Example: https://github.com/apache/druid/actions/runs/34431507380/job/102727804299 (failed all 4 surefire attempts).
KubernetesTaskRunner.start()schedulesdeleteCompletedPeonJobsOlderThanon a realScheduledExecutorServicewith an initial delay of 1 ms. Whether the first cleanup runs before the test'sverifyAll()depends on thread scheduling, so the strict mock sometimes sees a call it was not told to expect.Changes
runner.start()on a locally created runner, expectdeleteCompletedPeonJobsOlderThan(anyLong(), MILLISECONDS)any number of times via a small helper. Only this one call is relaxed; the rest ofpeonClientstays strictly verified.finallyblock so the cleanup executor does not outlive the test.Verified locally with
mvn -pl extensions-core/kubernetes-overlord-extensions test -Dtest=KubernetesTaskRunnerTest.Key changed/added classes in this PR
KubernetesTaskRunnerTestThis PR has:
Additional CI evidence
This same scheduled-cleanup race reappeared as a recovered flaky failure in PR #20330, unit-test job:
The corresponding PR #20329 unit run did not reach this assertion: its embedded tests failed earlier with
NoClassDefFoundError: org/apache/curator/test/TestingServerafter thecurator-testdependency was removed.