From ed1823a6c284d348a72dae8df228122fcb4d30d1 Mon Sep 17 00:00:00 2001 From: songlh Date: Thu, 16 Dec 2021 23:31:11 -0500 Subject: [PATCH 1/5] fixing three goroutine leaks in bounded_frequency_runner_test.go --- pkg/util/async/bounded_frequency_runner_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/util/async/bounded_frequency_runner_test.go b/pkg/util/async/bounded_frequency_runner_test.go index 1f9791af878..898ea016174 100644 --- a/pkg/util/async/bounded_frequency_runner_test.go +++ b/pkg/util/async/bounded_frequency_runner_test.go @@ -277,6 +277,7 @@ func Test_BoundedFrequencyRunnerNoBurst(t *testing.T) { // Clean up. stop <- struct{}{} + <- time.updated } func Test_BoundedFrequencyRunnerBurst(t *testing.T) { @@ -358,6 +359,7 @@ func Test_BoundedFrequencyRunnerBurst(t *testing.T) { // Clean up. stop <- struct{}{} + <- time.updated } func Test_BoundedFrequencyRunnerRetryAfter(t *testing.T) { @@ -441,4 +443,5 @@ func Test_BoundedFrequencyRunnerRetryAfter(t *testing.T) { // Clean up. stop <- struct{}{} + <- time.updated } From 8886e58ae95fda0e68762d0028e3ec7942133503 Mon Sep 17 00:00:00 2001 From: songlh Date: Fri, 17 Dec 2021 15:22:27 -0500 Subject: [PATCH 2/5] add comments to the fix --- pkg/util/async/bounded_frequency_runner_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/util/async/bounded_frequency_runner_test.go b/pkg/util/async/bounded_frequency_runner_test.go index 898ea016174..348169fb4e8 100644 --- a/pkg/util/async/bounded_frequency_runner_test.go +++ b/pkg/util/async/bounded_frequency_runner_test.go @@ -277,7 +277,9 @@ func Test_BoundedFrequencyRunnerNoBurst(t *testing.T) { // Clean up. stop <- struct{}{} - <- time.updated + //a message is sent to time.updated in func Stop() at the end of the child goroutine + //to terminate the child, a receive on time.updated is needed here + <- time.updated } func Test_BoundedFrequencyRunnerBurst(t *testing.T) { @@ -359,6 +361,8 @@ func Test_BoundedFrequencyRunnerBurst(t *testing.T) { // Clean up. stop <- struct{}{} + //a message is sent to time.updated in func Stop() at the end of the child goroutine + //to terminate the child, a receive on time.updated is needed here <- time.updated } @@ -443,5 +447,7 @@ func Test_BoundedFrequencyRunnerRetryAfter(t *testing.T) { // Clean up. stop <- struct{}{} + //a message is sent to time.updated in func Stop() at the end of the child goroutine + //to terminate the child, a receive on time.updated is needed here <- time.updated } From a108393b8cdd052e9aaf0f960ac64b1919051cf9 Mon Sep 17 00:00:00 2001 From: songlh Date: Fri, 17 Dec 2021 15:41:34 -0500 Subject: [PATCH 3/5] add spaces to comments --- pkg/util/async/bounded_frequency_runner_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/util/async/bounded_frequency_runner_test.go b/pkg/util/async/bounded_frequency_runner_test.go index 348169fb4e8..9601d0c1694 100644 --- a/pkg/util/async/bounded_frequency_runner_test.go +++ b/pkg/util/async/bounded_frequency_runner_test.go @@ -277,8 +277,8 @@ func Test_BoundedFrequencyRunnerNoBurst(t *testing.T) { // Clean up. stop <- struct{}{} - //a message is sent to time.updated in func Stop() at the end of the child goroutine - //to terminate the child, a receive on time.updated is needed here + // a message is sent to time.updated in func Stop() at the end of the child goroutine + // to terminate the child, a receive on time.updated is needed here <- time.updated } @@ -361,8 +361,8 @@ func Test_BoundedFrequencyRunnerBurst(t *testing.T) { // Clean up. stop <- struct{}{} - //a message is sent to time.updated in func Stop() at the end of the child goroutine - //to terminate the child, a receive on time.updated is needed here + // a message is sent to time.updated in func Stop() at the end of the child goroutine + // to terminate the child, a receive on time.updated is needed here <- time.updated } @@ -447,7 +447,7 @@ func Test_BoundedFrequencyRunnerRetryAfter(t *testing.T) { // Clean up. stop <- struct{}{} - //a message is sent to time.updated in func Stop() at the end of the child goroutine - //to terminate the child, a receive on time.updated is needed here + // a message is sent to time.updated in func Stop() at the end of the child goroutine + // to terminate the child, a receive on time.updated is needed here <- time.updated } From d4f3dde804fefd85eca6e03c3c7a9a94fe94a203 Mon Sep 17 00:00:00 2001 From: songlh Date: Fri, 17 Dec 2021 16:03:46 -0500 Subject: [PATCH 4/5] time -> timer --- pkg/util/async/bounded_frequency_runner_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/util/async/bounded_frequency_runner_test.go b/pkg/util/async/bounded_frequency_runner_test.go index 9601d0c1694..83ceb95016d 100644 --- a/pkg/util/async/bounded_frequency_runner_test.go +++ b/pkg/util/async/bounded_frequency_runner_test.go @@ -279,7 +279,7 @@ func Test_BoundedFrequencyRunnerNoBurst(t *testing.T) { stop <- struct{}{} // a message is sent to time.updated in func Stop() at the end of the child goroutine // to terminate the child, a receive on time.updated is needed here - <- time.updated + <- timer.updated } func Test_BoundedFrequencyRunnerBurst(t *testing.T) { @@ -363,7 +363,7 @@ func Test_BoundedFrequencyRunnerBurst(t *testing.T) { stop <- struct{}{} // a message is sent to time.updated in func Stop() at the end of the child goroutine // to terminate the child, a receive on time.updated is needed here - <- time.updated + <- timer.updated } func Test_BoundedFrequencyRunnerRetryAfter(t *testing.T) { @@ -449,5 +449,5 @@ func Test_BoundedFrequencyRunnerRetryAfter(t *testing.T) { stop <- struct{}{} // a message is sent to time.updated in func Stop() at the end of the child goroutine // to terminate the child, a receive on time.updated is needed here - <- time.updated + <- timer.updated } From 8cceaa051d826bd5a071967132fe1b236ccb9618 Mon Sep 17 00:00:00 2001 From: songlh Date: Fri, 17 Dec 2021 17:35:09 -0500 Subject: [PATCH 5/5] apply gofmt --- pkg/util/async/bounded_frequency_runner_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/util/async/bounded_frequency_runner_test.go b/pkg/util/async/bounded_frequency_runner_test.go index 83ceb95016d..333adabcf79 100644 --- a/pkg/util/async/bounded_frequency_runner_test.go +++ b/pkg/util/async/bounded_frequency_runner_test.go @@ -279,7 +279,7 @@ func Test_BoundedFrequencyRunnerNoBurst(t *testing.T) { stop <- struct{}{} // a message is sent to time.updated in func Stop() at the end of the child goroutine // to terminate the child, a receive on time.updated is needed here - <- timer.updated + <-timer.updated } func Test_BoundedFrequencyRunnerBurst(t *testing.T) { @@ -363,7 +363,7 @@ func Test_BoundedFrequencyRunnerBurst(t *testing.T) { stop <- struct{}{} // a message is sent to time.updated in func Stop() at the end of the child goroutine // to terminate the child, a receive on time.updated is needed here - <- timer.updated + <-timer.updated } func Test_BoundedFrequencyRunnerRetryAfter(t *testing.T) { @@ -449,5 +449,5 @@ func Test_BoundedFrequencyRunnerRetryAfter(t *testing.T) { stop <- struct{}{} // a message is sent to time.updated in func Stop() at the end of the child goroutine // to terminate the child, a receive on time.updated is needed here - <- timer.updated + <-timer.updated }