promqltest: scope ST/XOR2 storage options to package-internal tests

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 <gyorgy.krajcsovits@grafana.com>
This commit is contained in:
György Krajcsovits 2026-03-25 11:38:18 +01:00
parent b2ff1e5a5f
commit d5dd9044bb
No known key found for this signature in database
GPG Key ID: 47A8F9CE80FD7C7F
2 changed files with 18 additions and 5 deletions

View File

@ -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

View File

@ -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