fix: make TestWaitExecHandleHooks deterministic for 2-container hook ordering#9944
Open
lubronzhan wants to merge 1 commit into
Open
fix: make TestWaitExecHandleHooks deterministic for 2-container hook ordering#9944lubronzhan wants to merge 1 commit into
lubronzhan wants to merge 1 commit into
Conversation
👷 Deploy request for velero pending review.Visit the deploys page to approve it
|
lubronzhan
added a commit
to lubronzhan/velero
that referenced
this pull request
Jun 24, 2026
Signed-off-by: Lubron Zhan <lubron.zhan@broadcom.com> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
784e27d to
80dc42b
Compare
80dc42b to
8ecc531
Compare
There was a problem hiding this comment.
Pull request overview
This PR makes TestWaitExecHandleHooks deterministic by synchronizing pod state transitions with hook execution to avoid informer update coalescing that can skip intermediate pod states, eliminating a known flake in the 2-container hook ordering scenario.
Changes:
- Adds channel-based synchronization (
waitForSignal/onCalled) to control when subsequent fake pod updates are emitted. - Updates test comments to reflect informer coalescing behavior.
- Adds an unreleased changelog entry describing the flaky-test fix.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
internal/hook/wait_exec_hook_handler_test.go |
Introduces synchronization hooks to make the flaky 2-container ordering test deterministic. |
changelogs/unreleased/9944-lubronzhan |
Documents the test flake fix in the unreleased changelog. |
Comments suppressed due to low confidence (1)
internal/hook/wait_exec_hook_handler_test.go:743
waitForSignalcan deadlock the test indefinitely if the expected hook never fires (e.g., a regression preventsExecutePodCommandfrom being invoked), because the pod-update goroutine blocks forever and prevents later state transitions. Add a bounded wait (or tie it to context cancellation) so failures fail fast instead of hanging the entire test run.
Result(),
groupResource: "pods",
byContainer: map[string][]PodExecRestoreHook{
"container1": {
{
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
cbe3d90 to
134a54d
Compare
…ordering Fixes a flaky test in TestWaitExecHandleHooks: "should return no error with 2 spec hooks in 2 different containers, 1st container starts running after 10ms, 2nd container after 20ms, both succeed" Observed failure (CI run https://github.com/velero-io/velero/actions/runs/28119573625/job/83267758421): mock: Unexpected Method Call ExecutePodCommand called with resourceVersion:"3" (both containers running), but mock was registered expecting resourceVersion:"2" (container1 running, container2 still waiting). Root cause: the two source.Modify calls were 10ms apart. The informer's DeltaFIFO queue can coalesce rapid updates, delivering only the latest pod state (resourceVersion:3) to the handler before the hook for container1 fires. The comment "each of these states will be seen by the UpdateFunc handler" was incorrect — intermediate states can be silently skipped under load. Fix: add waitForSignal chan struct{} to the change struct and onCalled func() to the expectedExecution struct. The goroutine now blocks after sending the first change until the mock signals that the hook has fired (via close), then sends the second change. This guarantees the handler observes the intermediate pod state (resourceVersion:2) when executing container1's hook. Signed-off-by: Lubron Zhan <lubronzhan@gmail.com> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
134a54d to
f624362
Compare
reasonerjt
approved these changes
Jul 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Observed a flaky test from this PR #9943
TestWaitExecHandleHooks: "should return no error with 2 spec hooks in 2 different containers, 1st container starts running after 10ms, 2nd container after 20ms, both succeed"source.Modifycalls, delivering only the latest pod state to the handler before the first hook fires — so the mock was called withresourceVersion:3(both containers running) instead of the expectedresourceVersion:2(container1 running, container2 waiting)waitForSignal chan struct{}onchangeandonCalled func()onexpectedExecutionto synchronize the goroutine emitting changes with hook execution, making the test 100% deterministicObserved failure
CI run: https://github.com/velero-io/velero/actions/runs/28119573625/job/83267758421
The comment "Each of these states will be seen by the UpdateFunc handler" was incorrect — under load the FIFO can skip intermediate states.
Test plan
go test ./internal/hook/... -run TestWaitExecHandleHooks -count=20— all pass🤖 Generated with Claude Code