From d5dd9044bbc98fbc19af5bf04cfd4bf017e14490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gy=C3=B6rgy=20Krajcsovits?= Date: Wed, 25 Mar 2026 11:38:18 +0100 Subject: [PATCH] promqltest: scope ST/XOR2 storage options to package-internal tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit newTestStorage was enabling ST storage and XOR2 encoding globally, which broke unrelated tests (e.g. TestStreamReadEndpoint) in other packages that call RunBuiltinTests. Instead, keep newTestStorage as a simple teststorage.New wrapper and introduce a testStorageOptions package variable. An init() in the internal test file sets it to enable ST and XOR2, so the options only apply when the promqltest package itself is under test. Coded with Claude Sonnet 4.6. Signed-off-by: György Krajcsovits --- promql/promqltest/test.go | 12 +++++++----- promql/promqltest/test_test.go | 11 +++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/promql/promqltest/test.go b/promql/promqltest/test.go index f3a578a9ab..cc02a5b40f 100644 --- a/promql/promqltest/test.go +++ b/promql/promqltest/test.go @@ -39,7 +39,6 @@ import ( "github.com/prometheus/prometheus/promql/parser" "github.com/prometheus/prometheus/promql/parser/posrange" "github.com/prometheus/prometheus/storage" - "github.com/prometheus/prometheus/tsdb" "github.com/prometheus/prometheus/util/almost" "github.com/prometheus/prometheus/util/annotations" "github.com/prometheus/prometheus/util/convertnhcb" @@ -254,11 +253,14 @@ func newTest(t testing.TB, input string, testingMode bool, newStorage func(testi return test, err } +// testStorageOptions holds additional tsdb.Options applied by newTestStorage. +// It is populated via init() in test files so that options only take effect +// when the promqltest package itself is under test, not when callers such as +// promql_test.go invoke RunBuiltinTests. +var testStorageOptions []teststorage.Option + func newTestStorage(t testing.TB) storage.Storage { - return teststorage.New(t, func(opts *tsdb.Options) { - opts.EnableSTStorage = true - opts.EnableXOR2Encoding = true - }) + return teststorage.New(t, testStorageOptions...) } //go:embed testdata diff --git a/promql/promqltest/test_test.go b/promql/promqltest/test_test.go index ef0203b993..7634eabde0 100644 --- a/promql/promqltest/test_test.go +++ b/promql/promqltest/test_test.go @@ -24,9 +24,20 @@ import ( "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/promql" "github.com/prometheus/prometheus/promql/parser" + "github.com/prometheus/prometheus/tsdb" "github.com/prometheus/prometheus/tsdb/chunkenc" + "github.com/prometheus/prometheus/util/teststorage" ) +func init() { + testStorageOptions = []teststorage.Option{ + func(opts *tsdb.Options) { + opts.EnableSTStorage = true + opts.EnableXOR2Encoding = true + }, + } +} + func TestLazyLoader_WithSamplesTill(t *testing.T) { type testCase struct { ts time.Time