Skip to content

Commit

Permalink
Remove source of flakiness by using sync.Cond
Browse files Browse the repository at this point in the history
Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
  • Loading branch information
fpetkovski committed Aug 31, 2022
1 parent 646079f commit 348a8b3
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions pkg/queryfrontend/roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,6 @@ func TestRoundTripQueryCacheWithShardingMiddleware(t *testing.T) {
}

testutil.Equals(t, tc.expected, *res)

//if *res > tc.expected {
// t.Fatalf("Expected to get less than or exactly %d requests, got %d", tc.expected, *res)
//}
}) {
break
}
Expand Down Expand Up @@ -844,6 +840,8 @@ func promqlResultsWithFailures(numFailures int) (*int, http.Handler) {
},
}

cond := sync.NewCond(&sync.Mutex{})
cond.L.Lock()
return &count, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
lock.Lock()
defer lock.Unlock()
Expand All @@ -852,16 +850,21 @@ func promqlResultsWithFailures(numFailures int) (*int, http.Handler) {
if numFailures > 0 {
numFailures--

// Allow other requests to execute
lock.Unlock()
<-time.After(200 * time.Millisecond)
lock.Lock()

// Wait for a successful request.
// Release the lock to allow other requests to execute.
if numFailures == 0 {
lock.Unlock()
cond.Wait()
lock.Lock()
}
w.WriteHeader(500)
} else {
cond.Broadcast()
}
if err := json.NewEncoder(w).Encode(q); err != nil {
panic(err)
}

count++
})
}
Expand Down

0 comments on commit 348a8b3

Please sign in to comment.