From 0e82a96e2f2ecb0110cdfad014aaa6babf4f4941 Mon Sep 17 00:00:00 2001 From: Shihao Xia Date: Sat, 27 Nov 2021 07:45:06 -0500 Subject: [PATCH] fix potential deadlock in test (#9010) * fix potential deadlock Signed-off-by: Shihao Xia * fix deadlock Signed-off-by: Shihao Xia * Update promql/engine_test.go Co-authored-by: Ganesh Vernekar <15064823+codesome@users.noreply.github.com> Signed-off-by: Shihao Xia Co-authored-by: Ganesh Vernekar <15064823+codesome@users.noreply.github.com> --- promql/engine_test.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/promql/engine_test.go b/promql/engine_test.go index 17531e381..f7f6b216f 100644 --- a/promql/engine_test.go +++ b/promql/engine_test.go @@ -58,10 +58,19 @@ func TestQueryConcurrency(t *testing.T) { block := make(chan struct{}) processing := make(chan struct{}) + done := make(chan int) + defer close(done) f := func(context.Context) error { - processing <- struct{}{} - <-block + select { + case processing <- struct{}{}: + case <-done: + } + + select { + case <-block: + case <-done: + } return nil } @@ -370,7 +379,6 @@ func TestSelectHintsSetCorrectly(t *testing.T) { {Start: -45000, End: 80000, Func: "count_over_time"}, }, }, { - query: "foo", start: 10000, end: 20000, expected: []*storage.SelectHints{ {Start: 5000, End: 20000, Step: 1000},