mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
test: move most PromQL tests into separate test package
So that they can import promqltest which imports promql. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
4a72607c4a
commit
0dbfd20b69
|
@ -11,7 +11,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package promql
|
||||
package promql_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -23,13 +23,14 @@ import (
|
|||
|
||||
"github.com/prometheus/prometheus/model/histogram"
|
||||
"github.com/prometheus/prometheus/model/labels"
|
||||
"github.com/prometheus/prometheus/promql"
|
||||
"github.com/prometheus/prometheus/promql/parser"
|
||||
"github.com/prometheus/prometheus/storage"
|
||||
"github.com/prometheus/prometheus/tsdb/tsdbutil"
|
||||
"github.com/prometheus/prometheus/util/teststorage"
|
||||
)
|
||||
|
||||
func setupRangeQueryTestData(stor *teststorage.TestStorage, _ *Engine, interval, numIntervals int) error {
|
||||
func setupRangeQueryTestData(stor *teststorage.TestStorage, _ *promql.Engine, interval, numIntervals int) error {
|
||||
ctx := context.Background()
|
||||
|
||||
metrics := []labels.Labels{}
|
||||
|
@ -249,13 +250,13 @@ func BenchmarkRangeQuery(b *testing.B) {
|
|||
stor := teststorage.New(b)
|
||||
stor.DB.DisableCompactions() // Don't want auto-compaction disrupting timings.
|
||||
defer stor.Close()
|
||||
opts := EngineOpts{
|
||||
opts := promql.EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxSamples: 50000000,
|
||||
Timeout: 100 * time.Second,
|
||||
}
|
||||
engine := NewEngine(opts)
|
||||
engine := promql.NewEngine(opts)
|
||||
|
||||
const interval = 10000 // 10s interval.
|
||||
// A day of data plus 10k steps.
|
||||
|
@ -324,7 +325,7 @@ func BenchmarkNativeHistograms(b *testing.B) {
|
|||
},
|
||||
}
|
||||
|
||||
opts := EngineOpts{
|
||||
opts := promql.EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxSamples: 50000000,
|
||||
|
@ -338,7 +339,7 @@ func BenchmarkNativeHistograms(b *testing.B) {
|
|||
|
||||
for _, tc := range cases {
|
||||
b.Run(tc.name, func(b *testing.B) {
|
||||
ng := NewEngine(opts)
|
||||
ng := promql.NewEngine(opts)
|
||||
for i := 0; i < b.N; i++ {
|
||||
qry, err := ng.NewRangeQuery(context.Background(), testStorage, nil, tc.query, start, end, step)
|
||||
if err != nil {
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -11,7 +11,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package promql
|
||||
package promql_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -22,6 +22,7 @@ import (
|
|||
|
||||
"github.com/prometheus/prometheus/model/labels"
|
||||
"github.com/prometheus/prometheus/model/timestamp"
|
||||
"github.com/prometheus/prometheus/promql"
|
||||
"github.com/prometheus/prometheus/promql/parser"
|
||||
"github.com/prometheus/prometheus/util/teststorage"
|
||||
)
|
||||
|
@ -32,13 +33,13 @@ func TestDeriv(t *testing.T) {
|
|||
// so we test it by hand.
|
||||
storage := teststorage.New(t)
|
||||
defer storage.Close()
|
||||
opts := EngineOpts{
|
||||
opts := promql.EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxSamples: 10000,
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
engine := NewEngine(opts)
|
||||
engine := promql.NewEngine(opts)
|
||||
|
||||
a := storage.Appender(context.Background())
|
||||
|
||||
|
@ -69,13 +70,13 @@ func TestDeriv(t *testing.T) {
|
|||
|
||||
func TestFunctionList(t *testing.T) {
|
||||
// Test that Functions and parser.Functions list the same functions.
|
||||
for i := range FunctionCalls {
|
||||
for i := range promql.FunctionCalls {
|
||||
_, ok := parser.Functions[i]
|
||||
require.True(t, ok, "function %s exists in promql package, but not in parser package", i)
|
||||
}
|
||||
|
||||
for i := range parser.Functions {
|
||||
_, ok := FunctionCalls[i]
|
||||
_, ok := promql.FunctionCalls[i]
|
||||
require.True(t, ok, "function %s exists in parser package, but not in promql package", i)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package promql
|
||||
package promql_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -22,11 +22,12 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/prometheus/prometheus/promql"
|
||||
"github.com/prometheus/prometheus/promql/promqltest"
|
||||
"github.com/prometheus/prometheus/util/teststorage"
|
||||
)
|
||||
|
||||
func newTestEngine() *Engine {
|
||||
func newTestEngine() *promql.Engine {
|
||||
return promqltest.NewTestEngine(false, 0, promqltest.DefaultMaxSamplesPerQuery)
|
||||
}
|
||||
|
||||
|
@ -38,13 +39,13 @@ func TestEvaluations(t *testing.T) {
|
|||
func TestConcurrentRangeQueries(t *testing.T) {
|
||||
stor := teststorage.New(t)
|
||||
defer stor.Close()
|
||||
opts := EngineOpts{
|
||||
opts := promql.EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxSamples: 50000000,
|
||||
Timeout: 100 * time.Second,
|
||||
}
|
||||
engine := NewEngine(opts)
|
||||
engine := promql.NewEngine(opts)
|
||||
|
||||
const interval = 10000 // 10s interval.
|
||||
// A day of data plus 10k steps.
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package promql
|
||||
package promql_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
@ -19,39 +19,40 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/prometheus/prometheus/model/labels"
|
||||
"github.com/prometheus/prometheus/promql"
|
||||
)
|
||||
|
||||
func TestVector_ContainsSameLabelset(t *testing.T) {
|
||||
for name, tc := range map[string]struct {
|
||||
vector Vector
|
||||
vector promql.Vector
|
||||
expected bool
|
||||
}{
|
||||
"empty vector": {
|
||||
vector: Vector{},
|
||||
vector: promql.Vector{},
|
||||
expected: false,
|
||||
},
|
||||
"vector with one series": {
|
||||
vector: Vector{
|
||||
vector: promql.Vector{
|
||||
{Metric: labels.FromStrings("lbl", "a")},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
"vector with two different series": {
|
||||
vector: Vector{
|
||||
vector: promql.Vector{
|
||||
{Metric: labels.FromStrings("lbl", "a")},
|
||||
{Metric: labels.FromStrings("lbl", "b")},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
"vector with two equal series": {
|
||||
vector: Vector{
|
||||
vector: promql.Vector{
|
||||
{Metric: labels.FromStrings("lbl", "a")},
|
||||
{Metric: labels.FromStrings("lbl", "a")},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
"vector with three series, two equal": {
|
||||
vector: Vector{
|
||||
vector: promql.Vector{
|
||||
{Metric: labels.FromStrings("lbl", "a")},
|
||||
{Metric: labels.FromStrings("lbl", "b")},
|
||||
{Metric: labels.FromStrings("lbl", "a")},
|
||||
|
@ -67,35 +68,35 @@ func TestVector_ContainsSameLabelset(t *testing.T) {
|
|||
|
||||
func TestMatrix_ContainsSameLabelset(t *testing.T) {
|
||||
for name, tc := range map[string]struct {
|
||||
matrix Matrix
|
||||
matrix promql.Matrix
|
||||
expected bool
|
||||
}{
|
||||
"empty matrix": {
|
||||
matrix: Matrix{},
|
||||
matrix: promql.Matrix{},
|
||||
expected: false,
|
||||
},
|
||||
"matrix with one series": {
|
||||
matrix: Matrix{
|
||||
matrix: promql.Matrix{
|
||||
{Metric: labels.FromStrings("lbl", "a")},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
"matrix with two different series": {
|
||||
matrix: Matrix{
|
||||
matrix: promql.Matrix{
|
||||
{Metric: labels.FromStrings("lbl", "a")},
|
||||
{Metric: labels.FromStrings("lbl", "b")},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
"matrix with two equal series": {
|
||||
matrix: Matrix{
|
||||
matrix: promql.Matrix{
|
||||
{Metric: labels.FromStrings("lbl", "a")},
|
||||
{Metric: labels.FromStrings("lbl", "a")},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
"matrix with three series, two equal": {
|
||||
matrix: Matrix{
|
||||
matrix: promql.Matrix{
|
||||
{Metric: labels.FromStrings("lbl", "a")},
|
||||
{Metric: labels.FromStrings("lbl", "b")},
|
||||
{Metric: labels.FromStrings("lbl", "a")},
|
||||
|
|
Loading…
Reference in a new issue