Skip to content

Commit

Permalink
Improve fuzz test to skip non-deterministic query
Browse files Browse the repository at this point in the history
Signed-off-by: SungJin1212 <[email protected]>
  • Loading branch information
SungJin1212 committed Nov 20, 2024
1 parent 71dccee commit 27fd5ea
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions integration/query_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,7 @@ func runQueryFuzzTestCases(t *testing.T, ps *promqlsmith.PromQLSmith, c1, c2 *e2
expr parser.Expr
query string
)
runForNonDeterCheck := 3
for i := 0; i < run; i++ {
for {
expr = ps.WalkInstantQuery()
Expand All @@ -1354,6 +1355,30 @@ func runQueryFuzzTestCases(t *testing.T, ps *promqlsmith.PromQLSmith, c1, c2 *e2
break
}
}

nonDeterministicQuery := false
for i := 0; i < runForNonDeterCheck; i++ {
r1, err1 := c2.Query(query, queryTime)
r2, err2 := c2.Query(query, queryTime)

if err1 != nil || err2 != nil {
if !cmp.Equal(err1, err2) {
nonDeterministicQuery = true
break
}
}

if !cmp.Equal(r1, r2, comparer) {
nonDeterministicQuery = true
break
}
}

if nonDeterministicQuery {
t.Logf("the instant query result is a non-determisic, query: %s, skip", query)
continue
}

res1, err1 := c1.Query(query, queryTime)
res2, err2 := c2.Query(query, queryTime)
cases = append(cases, &testCase{
Expand All @@ -1374,6 +1399,30 @@ func runQueryFuzzTestCases(t *testing.T, ps *promqlsmith.PromQLSmith, c1, c2 *e2
break
}
}

nonDeterministicQuery := false
for i := 0; i < runForNonDeterCheck; i++ {
r1, err1 := c2.QueryRange(query, start, end, step)
r2, err2 := c2.QueryRange(query, start, end, step)

if err1 != nil || err2 != nil {
if !cmp.Equal(err1, err2) {
nonDeterministicQuery = true
break
}
}

if !cmp.Equal(r1, r2, comparer) {
nonDeterministicQuery = true
break
}
}

if nonDeterministicQuery {
t.Logf("the range query result is a non-determisic, query: %s, skip", query)
continue
}

res1, err1 := c1.QueryRange(query, start, end, step)
res2, err2 := c2.QueryRange(query, start, end, step)
cases = append(cases, &testCase{
Expand Down

0 comments on commit 27fd5ea

Please sign in to comment.