-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
[ENV-40] debounce refresh requests with quietperiod #10172
Conversation
Codecov ReportBase: 73.89% // Head: 72.79% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## v2 #10172 +/- ##
==========================================
- Coverage 73.89% 72.79% -1.11%
==========================================
Files 2 2
Lines 272 272
==========================================
- Hits 201 198 -3
- Misses 60 62 +2
- Partials 11 12 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
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.
🏃
pkg/compose/watch.go
Outdated
case <-ctx.Done(): | ||
return | ||
case service := <-input: | ||
timer.Reset(interval) |
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.
Since we don't know if the timer has fired here, we need to stop it/drain first:
if !timer.Stop() {
<-timer.C
}
timer.Reset(interval)
pkg/compose/watch.go
Outdated
needRefresh := make(chan string) | ||
eg.Go(func() error { | ||
debounce(ctx, quietPeriod, needRefresh, func(services []string) { | ||
fmt.Fprintf(s.stderr(), "Updating %s after changes were detected", strings.Join(services, ", ")) |
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.
fmt.Fprintf(s.stderr(), "Updating %s after changes were detected", strings.Join(services, ", ")) | |
fmt.Fprintf(s.stderr(), "Updating %s after changes were detected\n", strings.Join(services, ", ")) |
(Missing \n
)
"gotest.tools/v3/assert" | ||
) | ||
|
||
func Test_debounce(t *testing.T) { |
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 might take a look at Go libs out there to help with controlling timers deterministically in tests, as this is likely to become a problematic/failing test in CI otherwise
Tilt uses this library fairly extensively: https://github.com/jonboulle/clockwork
It provides a clock, which is either the real one (i.e. pass calls through to time.Time
) or a fake one where you can control when/how it advances
7b3905f
to
4137940
Compare
cb7e7c1
to
f67ddc1
Compare
fe4e453
to
acbae37
Compare
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
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.
LGTM
|
||
package utils | ||
|
||
type Set[T comparable] map[T]struct{} |
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.
😍
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.
one baby step...
What I did
As we capture fs events, collect them to list services which need to be updated, with debounce and a quiet period