From: Daniel Swarbrick <dswarbrick@debian.org>
Date: Sun, 31 Mar 2024 17:52:27 +0200
Subject: Fix deadlock in TestQuerierIndexQueriesRace

Origin: https://github.com/prometheus/prometheus/pull/12881

This fixes an apparent deadlock which can occur in this test on
single-core hosts.
---
 tsdb/querier_test.go | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tsdb/querier_test.go b/tsdb/querier_test.go
index 8cfd5d1..90e3385 100644
--- a/tsdb/querier_test.go
+++ b/tsdb/querier_test.go
@@ -2221,6 +2221,7 @@ func TestQuerierIndexQueriesRace(t *testing.T) {
 	for _, c := range testCases {
 		c := c
 		t.Run(fmt.Sprintf("%v", c.matchers), func(t *testing.T) {
+			t.Parallel()
 			db := openTestDB(t, DefaultOptions(), nil)
 			h := db.Head()
 			t.Cleanup(func() {
@@ -2240,6 +2241,9 @@ func TestQuerierIndexQueriesRace(t *testing.T) {
 				values, _, err := q.LabelValues("n", c.matchers...)
 				require.NoError(t, err)
 				require.Emptyf(t, values, `label values for label "n" should be empty`)
+
+				// Sleep to give the appends some change to run.
+				time.Sleep(time.Millisecond)
 			}
 		})
 	}
@@ -2256,6 +2260,7 @@ func appendSeries(t *testing.T, ctx context.Context, wg *sync.WaitGroup, h *Head
 		require.NoError(t, err)
 
 		// Throttle down the appends to keep the test somewhat nimble.
+		// Otherwise, we end up appending thousands or millions of samples.
 		time.Sleep(time.Millisecond)
 	}
 }
