diff --git a/promql/engine_test.go b/promql/engine_test.go index 5ca110824..59e707011 100644 --- a/promql/engine_test.go +++ b/promql/engine_test.go @@ -1289,13 +1289,10 @@ load 10s }, } - engine := newTestEngine() - engine.enablePerStepStats = true - origMaxSamples := engine.maxSamplesPerQuery for _, c := range cases { t.Run(c.Query, func(t *testing.T) { opts := promql.NewPrometheusQueryOpts(true, 0) - engine.maxSamplesPerQuery = origMaxSamples + engine := promqltest.NewTestEngine(true, 0, promqltest.DefaultMaxSamplesPerQuery) runQuery := func(expErr error) *stats.Statistics { var err error @@ -1322,7 +1319,7 @@ load 10s if c.SkipMaxCheck { return } - engine.maxSamplesPerQuery = stats.Samples.PeakSamples - 1 + engine = promqltest.NewTestEngine(true, 0, stats.Samples.PeakSamples-1) runQuery(promql.ErrTooManySamples(env)) }) } @@ -1496,11 +1493,11 @@ load 10s } // Within limit. - engine.maxSamplesPerQuery = c.MaxSamples + engine = promqltest.NewTestEngine(false, 0, c.MaxSamples) testFunc(nil) // Exceeding limit. - engine.maxSamplesPerQuery = c.MaxSamples - 1 + engine = promqltest.NewTestEngine(false, 0, c.MaxSamples-1) testFunc(promql.ErrTooManySamples(env)) }) } @@ -4956,13 +4953,10 @@ metric 0 1 2 for _, c := range cases { c := c t.Run(c.name, func(t *testing.T) { - engine := newTestEngine() + engine := promqltest.NewTestEngine(false, c.engineLookback, promqltest.DefaultMaxSamplesPerQuery) storage := promqltest.LoadedStorage(t, load) t.Cleanup(func() { storage.Close() }) - if c.engineLookback != 0 { - engine.lookbackDelta = c.engineLookback - } opts := promql.NewPrometheusQueryOpts(false, c.queryLookback) qry, err := engine.NewInstantQuery(context.Background(), storage, opts, query, c.ts) require.NoError(t, err) diff --git a/promql/promql_test.go b/promql/promql_test.go index 59ec4756e..7bafc02e3 100644 --- a/promql/promql_test.go +++ b/promql/promql_test.go @@ -32,7 +32,7 @@ func newTestEngine() *promql.Engine { } func TestEvaluations(t *testing.T) { - RunBuiltinTests(t, newTestEngine()) + promqltest.RunBuiltinTests(t, newTestEngine()) } // Run a lot of queries at the same time, to check for race conditions. diff --git a/promql/promqltest/test.go b/promql/promqltest/test.go index 1b2ce78af..1affd91f6 100644 --- a/promql/promqltest/test.go +++ b/promql/promqltest/test.go @@ -76,7 +76,7 @@ func NewTestEngine(enablePerStepStats bool, lookbackDelta time.Duration, maxSamp return promql.NewEngine(promql.EngineOpts{ Logger: nil, Reg: nil, - MaxSamples: DefaultMaxSamplesPerQuery, + MaxSamples: maxSamples, Timeout: 100 * time.Second, NoStepSubqueryIntervalFn: func(int64) int64 { return durationMilliseconds(1 * time.Minute) }, EnableAtModifier: true,