|
| 1 | +From 0e66dc19b9f93c247dd938f8099626573df0e998 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Dimitar Dimitrov <dimitar.dimitrov@grafana.com> |
| 3 | +Date: Thu, 21 Sep 2023 12:30:08 +0200 |
| 4 | +Subject: [PATCH] Improve sensitivity of TestQuerierIndexQueriesRace |
| 5 | + |
| 6 | +Currently, the two goroutines race against each other and it's possible that the main test goroutine finishes way earlier than appendSeries has had a chance to run at all. |
| 7 | + |
| 8 | +I tested this change by breaking the code that X fixed and running the race test 100 times. Without the additional time.Sleep the test failed 11 times. With the sleep it failed 65 out of the 100 runs. Which is still not ideal, but it's a step forward. |
| 9 | + |
| 10 | +Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com> |
| 11 | +--- |
| 12 | + tsdb/querier_test.go | 5 +++++ |
| 13 | + 1 file changed, 5 insertions(+) |
| 14 | + |
| 15 | +diff --git a/tsdb/querier_test.go b/tsdb/querier_test.go |
| 16 | +index 2c5ff7477..4938443c2 100644 |
| 17 | +--- a/tsdb/querier_test.go |
| 18 | ++++ b/tsdb/querier_test.go |
| 19 | +@@ -2221,6 +2221,7 @@ func TestQuerierIndexQueriesRace(t *testing.T) { |
| 20 | + for _, c := range testCases { |
| 21 | + c := c |
| 22 | + t.Run(fmt.Sprintf("%v", c.matchers), func(t *testing.T) { |
| 23 | ++ t.Parallel() |
| 24 | + db := openTestDB(t, DefaultOptions(), nil) |
| 25 | + h := db.Head() |
| 26 | + t.Cleanup(func() { |
| 27 | +@@ -2240,6 +2241,9 @@ func TestQuerierIndexQueriesRace(t *testing.T) { |
| 28 | + values, _, err := q.LabelValues("n", c.matchers...) |
| 29 | + require.NoError(t, err) |
| 30 | + require.Emptyf(t, values, `label values for label "n" should be empty`) |
| 31 | ++ |
| 32 | ++ // Sleep to give the appends some change to run. |
| 33 | ++ time.Sleep(time.Millisecond) |
| 34 | + } |
| 35 | + }) |
| 36 | + } |
| 37 | +@@ -2256,6 +2260,7 @@ func appendSeries(t *testing.T, ctx context.Context, wg *sync.WaitGroup, h *Head |
| 38 | + require.NoError(t, err) |
| 39 | + |
| 40 | + // Throttle down the appends to keep the test somewhat nimble. |
| 41 | ++ // Otherwise, we end up appending thousands or millions of samples. |
| 42 | + time.Sleep(time.Millisecond) |
| 43 | + } |
| 44 | + } |
| 45 | +-- |
| 46 | +2.33.8 |
| 47 | + |
0 commit comments