Fix flaky test

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Arve Knudsen 2024-05-15 21:58:56 +02:00
parent bf8d88f326
commit 0f01d4b336

View file

@ -21,6 +21,7 @@ import (
"os" "os"
"sort" "sort"
"strconv" "strconv"
"sync"
"testing" "testing"
"time" "time"
@ -94,9 +95,14 @@ func TestQueryConcurrency(t *testing.T) {
return nil return nil
} }
var wg sync.WaitGroup
for i := 0; i < maxConcurrency; i++ { for i := 0; i < maxConcurrency; i++ {
q := engine.NewTestQuery(f) q := engine.NewTestQuery(f)
go q.Exec(ctx) wg.Add(1)
go func() {
q.Exec(ctx)
wg.Done()
}()
select { select {
case <-processing: case <-processing:
// Expected. // Expected.
@ -106,7 +112,11 @@ func TestQueryConcurrency(t *testing.T) {
} }
q := engine.NewTestQuery(f) q := engine.NewTestQuery(f)
go q.Exec(ctx) wg.Add(1)
go func() {
q.Exec(ctx)
wg.Done()
}()
select { select {
case <-processing: case <-processing:
@ -129,6 +139,8 @@ func TestQueryConcurrency(t *testing.T) {
for i := 0; i < maxConcurrency; i++ { for i := 0; i < maxConcurrency; i++ {
block <- struct{}{} block <- struct{}{}
} }
wg.Wait()
} }
// contextDone returns an error if the context was canceled or timed out. // contextDone returns an error if the context was canceled or timed out.