-
Notifications
You must be signed in to change notification settings - Fork 5.8k
remove jonboulle/clockwork for testing/synctest #14185
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
Open
thaJeztah
wants to merge
2
commits into
docker:main
Choose a base branch
from
thaJeztah:defake
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+116
−137
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,6 @@ import ( | |
| "context" | ||
| "time" | ||
|
|
||
| "github.com/jonboulle/clockwork" | ||
| "github.com/sirupsen/logrus" | ||
|
|
||
| "github.com/docker/compose/v5/pkg/utils" | ||
|
|
@@ -30,7 +29,7 @@ const QuietPeriod = 500 * time.Millisecond | |
| // channel. | ||
| // | ||
| // The returned channel is closed when the debouncer is stopped via context cancellation or by closing the input channel. | ||
| func BatchDebounceEvents(ctx context.Context, clock clockwork.Clock, input <-chan FileEvent) <-chan []FileEvent { | ||
| func BatchDebounceEvents(ctx context.Context, input <-chan FileEvent) <-chan []FileEvent { | ||
|
Comment on lines
31
to
+32
Member
Author
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. Not sure if this function is used outside of compose itself, because it's a signature change; if that's a problem, we can perhaps replace it with |
||
| out := make(chan []FileEvent) | ||
| go func() { | ||
| defer close(out) | ||
|
|
@@ -49,13 +48,13 @@ func BatchDebounceEvents(ctx context.Context, clock clockwork.Clock, input <-cha | |
| seen = utils.Set[FileEvent]{} | ||
| } | ||
|
|
||
| t := clock.NewTicker(QuietPeriod) | ||
| t := time.NewTicker(QuietPeriod) | ||
| defer t.Stop() | ||
| for { | ||
| select { | ||
| case <-ctx.Done(): | ||
| return | ||
| case <-t.Chan(): | ||
| case <-t.C: | ||
| flushEvents() | ||
| case e, ok := <-input: | ||
| if !ok { | ||
|
|
||
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
Oops, something went wrong.
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.
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.
[medium] Second test batch asserts no sync occurred, but
handleWatchBatchWILL callsyncer.Sync()— leaving a goroutine permanently blockedThe second event batch sends both
/rebuildand/sync/changed:/rebuildmatches theWatchActionRebuildrule → triggerss.rebuild(...)/sync/changedmatches theWatchActionSyncrule → triggerssyncer.Sync(...)which blocks on the unbufferedsyncer.synced <- pathshandleWatchBatchprocesses both actions (rebuild first, then sync viasyncfilesiteration — they are independent maps). Sosyncer.Sync()is called, and the goroutine durably blocks onf.synced <- paths(a bubble-internal channel send).After
synctest.Wait()returns (because all other goroutines are durably blocked), theselect { default: }branch is taken — the pending send onsyncer.syncedis never read. The blocked goroutine leaks inside the bubble. Whensynctest.Testexits and waits for all goroutines to finish, the test panics with a deadlock/goroutine-leak message rather than a clear failure.The original clockwork-based test used
time.After(100ms)as the "no sync" timeout, which would also time out incorrectly in this scenario — but the old test's assertion was already wrong before this PR (the test comment says// TODO: there's not a great way to assert that the rebuild attempt happened). The migration to synctest surfaces this latent bug as a hard panic.Fix options:
syncer.syncedafter the rebuild batch, then assert the contents were not pure-sync (or just drain it):/sync/changed), making the "no sync" assertion valid./sync/changedevent (since it matches a sync rule even in a rebuild batch), updating the test intention.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.
@docker-agent I think this is a false positive.
handleWatchBatchonly reaches the sync actions if the rebuild succeeds:In this test the rebuild intentionally fails (
invalid service "test". Must specify either image or build), sosyncer.Sync()is never called for the/sync/changedevent in that batch.That also explains the existing assertion and TODO: the mixed batch is useful to verify that sync processing does not continue after the rebuild failure, while the test doesn't have a clean way to directly assert the rebuild attempt itself.
With
synctest.Wait()followed by the non-blocking select, the original assertion remains valid and deterministic.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.
You're absolutely right — I misread the control flow. The early return on rebuild failure means
syncer.Sync()is never reached for the/sync/changedevent in the mixed batch, so the "no sync" assertion is correct.I've stored this pattern (early-return-on-rebuild-failure preventing downstream sync processing) to avoid flagging it incorrectly in future reviews. Thanks for the clarification and for explaining the test's intention — the mixed batch now makes much more sense as a deliberate verification that sync doesn't proceed after rebuild failures.