From afc05129f1b0dc678c2744bf3823d6a81fbf65d6 Mon Sep 17 00:00:00 2001 From: machine424 Date: Sun, 7 Jan 2024 20:57:53 +0100 Subject: [PATCH] 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 --- discovery/file/file_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/discovery/file/file_test.go b/discovery/file/file_test.go index c138fc8a9..731611832 100644 --- a/discovery/file/file_test.go +++ b/discovery/file/file_test.go @@ -193,9 +193,10 @@ func (t *testRunner) targets() []*targetgroup.Group { func (t *testRunner) requireUpdate(ref time.Time, expected []*targetgroup.Group) { t.Helper() + timeout := time.After(defaultWait) for { select { - case <-time.After(defaultWait): + case <-timeout: t.Fatalf("Expected update but got none") return case <-time.After(defaultWait / 10):