fix(discovery): allow requireUpdate util to timeout in discovery/file/file_test.go.

The loop ran indefinitely if the condition isn't met.

Before, each iteration created a new timer channel which was always outpaced by
the other timer channel with smaller duration.

minor detail: There was a memory leak: resources of the ~10 previous timers were
constantly kept. With the fix, we may keep the resources of one timer around for defaultWait
but this isn't worth the changes to make it right.

Signed-off-by: machine424 <ayoubmrini424@gmail.com>
This commit is contained in:
machine424 2024-01-07 20:57:53 +01:00
parent 78c5ce3196
commit afc05129f1
No known key found for this signature in database
GPG Key ID: A4B001A4FDEE017D
1 changed files with 2 additions and 1 deletions

View File

@ -193,9 +193,10 @@ func (t *testRunner) targets() []*targetgroup.Group {
func (t *testRunner) requireUpdate(ref time.Time, expected []*targetgroup.Group) { func (t *testRunner) requireUpdate(ref time.Time, expected []*targetgroup.Group) {
t.Helper() t.Helper()
timeout := time.After(defaultWait)
for { for {
select { select {
case <-time.After(defaultWait): case <-timeout:
t.Fatalf("Expected update but got none") t.Fatalf("Expected update but got none")
return return
case <-time.After(defaultWait / 10): case <-time.After(defaultWait / 10):