You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by "hanahmily (via GitHub)" <gi...@apache.org> on 2026/06/02 05:20:18 UTC
[PR] Add program-generated trace query integration-test framework [skywalking-banyandb]
hanahmily opened a new pull request, #1150:
URL: https://github.com/apache/skywalking-banyandb/pull/1150
## What
Adds the trace equivalent of the measure program-generated integration-test framework, establishing a golden baseline for trace queries.
### Generator (`test/cases/trace/cmd/generate`)
- **Layer 1** — criteria leaves: binary ops × value types over trace tags (`trace_id`/`service_id`/`state`/`duration`), plus error/empty cases.
- **Layer 2** — AND/OR criteria trees at depths {1, 2, 3, 5}.
- **Layer 3** — constraint-pruned pairwise across the two trace query modes (**traceID-lookup** via `WHERE trace_id` vs **order-based** via `ORDER BY <index_rule>`) × order rule/direction × filter × limit × offset × projection shape.
- Idempotent and additive (name-based gap filter never clobbers hand-written cases); a generate-time seed-mirror check guards the in-code seed against the JSON fixtures.
### Capture (`test/cases/trace/cmd/capture`)
- Env-gated (`CAPTURE_TRACE_WANT_FIXTURES=1`) so a routine `go test ./...` cannot silently re-baseline goldens.
- Boots a standalone server, seeds via the shared `SeedAll`, runs the same QL→proto round-trip the runtime verifier uses, and writes plain-string-span `want` files.
### Harness
- Extract `casestrace.SeedAll` (called by both `init.go` and capture, so captured goldens cannot drift from the live suite's seed), export `MarshalToJSONWithStringBytes`, add the trace `LicenseHeader`, wire 38 generated `g.Entry` lines into `traceEntries`, and add `make generate-trace-test-cases` / `make capture-trace-test-cases`.
## Tests
38 generated cases verified green by the standalone query integration suite. `make generate-trace-test-cases` is idempotent; goldens reproduce deterministically via capture.
## Notes
Builds on #1147 (merged) for the trace identity-tag projection + distributed span-alignment fixes that the explicit-projection and multi-span generated cases exercise.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add program-generated trace query integration-test framework [skywalking-banyandb]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #1150:
URL: https://github.com/apache/skywalking-banyandb/pull/1150#discussion_r3341292915
##########
test/cases/trace/cmd/generate/seed.go:
##########
@@ -0,0 +1,230 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package main
+
+import (
+ "encoding/json"
+ "fmt"
+ "os"
+ "path/filepath"
+ "slices"
+)
+
+// TagType describes a trace tag value type.
+type TagType int
+
+const (
+ TagTypeString TagType = iota
+ TagTypeInt
+ TagTypeTimestamp
+)
+
+// Role describes how generated tests use a tag.
+type Role int
+
+const (
+ RoleIdentity Role = iota
+ RoleIndexed
+ RolePlain
+)
+
+// TagDef describes a trace tag in positional seed order.
+type TagDef struct {
+ Name string
+ Type TagType
+ Pos int
+ Role Role
+}
+
+// SpanRow mirrors one seeded span row used for generation value selection.
+type SpanRow struct {
+ TagValues map[string]any
+ Span string
+}
+
+// Trace describes the trace schema and rows used by generated tests.
+type Trace struct {
+ Name string
+ Group string
+ Groups []string
+ Tags []TagDef
+ OrderRules []string
+ TraceIDTag string
+ SpanIDTag string
+ TimestampTag string
+ Rows []SpanRow
+}
+
+// SeedData returns trace schemas available to the generator.
+func SeedData() []Trace {
+ return []Trace{swTrace()}
+}
+
+// FindTrace returns a trace schema by name.
+func FindTrace(name string) *Trace {
+ for _, traceDef := range SeedData() {
+ if traceDef.Name == name {
+ return &traceDef
+ }
+ }
+ return nil
+}
Review Comment:
FindTrace returns the address of the range variable (a copy). This is a common Go pitfall and can lead to surprising behavior if the returned *Trace is ever mutated or compared by address. Return a pointer to the slice element instead.
##########
test/cases/trace/cmd/generate/pairwise.go:
##########
@@ -0,0 +1,174 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package main
+
+// Copied verbatim from test/cases/measure/cmd/generate/pairwise.go — keep in sync; pure combinatorics, no proto types.
+
+// Pair holds a parameter-value pair for pairwise testing.
+type Pair struct {
+ Param string
+ Value string
+}
+
+// TestVector is a set of parameter-value assignments.
+type TestVector map[string]string
+
+// PairwiseGenerate generates a minimal set of test vectors covering all pairs
+// of parameter values using a simplified IPO (In-Parameter-Order) algorithm.
+func PairwiseGenerate(params map[string][]string, constraints []ConstraintFunc) []TestVector {
+ paramNames := sortedParamNames(params)
+ if len(paramNames) == 0 {
+ return nil
+ }
+
+ // Collect all required pairs
+ requiredPairs := collectAllPairs(params, constraints)
+
+ // Build test vectors using greedy pair covering
+ var vectors []TestVector
+ coveredPairs := make(map[Pair]bool)
+
+ for len(coveredPairs) < len(requiredPairs) {
+ tv := buildVector(params, paramNames, coveredPairs, constraints)
+ if tv == nil {
+ break
+ }
+ // Mark newly covered pairs
+ newCovers := 0
+ for _, pn := range paramNames {
+ for _, pn2 := range paramNames {
+ if pn >= pn2 {
+ continue
+ }
+ p := Pair{Param: pn + "=" + tv[pn], Value: pn2 + "=" + tv[pn2]}
+ if !coveredPairs[p] {
+ coveredPairs[p] = true
+ newCovers++
+ }
+ }
+ }
+ if newCovers == 0 {
+ break
+ }
+ vectors = append(vectors, tv)
+ }
+ return vectors
+}
+
+// ConstraintFunc returns false if the combination is invalid.
+type ConstraintFunc func(tv TestVector) bool
+
+func collectAllPairs(params map[string][]string, constraints []ConstraintFunc) map[Pair]bool {
+ pairs := make(map[Pair]bool)
+ paramNames := sortedParamNames(params)
+ for _, pn := range paramNames {
+ for _, pn2 := range paramNames {
+ if pn >= pn2 {
+ continue
+ }
+ for _, v1 := range params[pn] {
+ for _, v2 := range params[pn2] {
+ tv := TestVector{pn: v1, pn2: v2}
+ if validConstraints(tv, constraints) {
+ pairs[Pair{Param: pn + "=" + v1, Value: pn2 + "=" + v2}] = true
+ }
+ }
+ }
+ }
+ }
+ return pairs
+}
+
+func buildVector(params map[string][]string, paramNames []string, coveredPairs map[Pair]bool, constraints []ConstraintFunc) TestVector {
+ tv := make(TestVector)
+ fillVector(tv, params, paramNames, 0, coveredPairs, constraints)
+ return tv
+}
+
+func fillVector(tv TestVector, params map[string][]string, paramNames []string, paramIdx int, coveredPairs map[Pair]bool, constraints []ConstraintFunc) bool {
+ if paramIdx >= len(paramNames) {
+ return validConstraints(tv, constraints)
+ }
+ pn := paramNames[paramIdx]
+ bestVal := ""
+ bestScore := -1
+ for _, val := range params[pn] {
+ tv[pn] = val
+ if !validConstraints(tv, constraints) {
+ continue
+ }
+ score := countNewPairs(tv, paramNames, paramIdx, coveredPairs)
+ if score > bestScore {
+ bestScore = score
+ bestVal = val
+ }
+ }
+ if bestVal == "" {
+ // Fallback: pick first valid value
+ for _, val := range params[pn] {
+ tv[pn] = val
+ if validConstraints(tv, constraints) {
+ bestVal = val
+ break
+ }
+ }
+ if bestVal == "" {
+ tv[pn] = params[pn][0]
+ }
+ }
+ tv[pn] = bestVal
+ return fillVector(tv, params, paramNames, paramIdx+1, coveredPairs, constraints)
Review Comment:
In fillVector's fallback path, when no value satisfies constraints, the code sets `tv[pn] = params[pn][0]` but never assigns `bestVal`. The subsequent `tv[pn] = bestVal` overwrites the fallback with an empty string, producing invalid vectors and potentially breaking pair coverage.
##########
test/cases/trace/cmd/generate/pairwise.go:
##########
@@ -0,0 +1,174 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package main
+
+// Copied verbatim from test/cases/measure/cmd/generate/pairwise.go — keep in sync; pure combinatorics, no proto types.
+
+// Pair holds a parameter-value pair for pairwise testing.
+type Pair struct {
+ Param string
+ Value string
+}
+
+// TestVector is a set of parameter-value assignments.
+type TestVector map[string]string
+
+// PairwiseGenerate generates a minimal set of test vectors covering all pairs
+// of parameter values using a simplified IPO (In-Parameter-Order) algorithm.
+func PairwiseGenerate(params map[string][]string, constraints []ConstraintFunc) []TestVector {
+ paramNames := sortedParamNames(params)
+ if len(paramNames) == 0 {
+ return nil
+ }
+
+ // Collect all required pairs
+ requiredPairs := collectAllPairs(params, constraints)
+
+ // Build test vectors using greedy pair covering
+ var vectors []TestVector
+ coveredPairs := make(map[Pair]bool)
+
+ for len(coveredPairs) < len(requiredPairs) {
+ tv := buildVector(params, paramNames, coveredPairs, constraints)
+ if tv == nil {
+ break
+ }
+ // Mark newly covered pairs
+ newCovers := 0
+ for _, pn := range paramNames {
+ for _, pn2 := range paramNames {
+ if pn >= pn2 {
+ continue
+ }
+ p := Pair{Param: pn + "=" + tv[pn], Value: pn2 + "=" + tv[pn2]}
+ if !coveredPairs[p] {
+ coveredPairs[p] = true
+ newCovers++
+ }
+ }
+ }
+ if newCovers == 0 {
+ break
+ }
+ vectors = append(vectors, tv)
+ }
+ return vectors
+}
+
+// ConstraintFunc returns false if the combination is invalid.
+type ConstraintFunc func(tv TestVector) bool
+
+func collectAllPairs(params map[string][]string, constraints []ConstraintFunc) map[Pair]bool {
+ pairs := make(map[Pair]bool)
+ paramNames := sortedParamNames(params)
+ for _, pn := range paramNames {
+ for _, pn2 := range paramNames {
+ if pn >= pn2 {
+ continue
+ }
+ for _, v1 := range params[pn] {
+ for _, v2 := range params[pn2] {
+ tv := TestVector{pn: v1, pn2: v2}
+ if validConstraints(tv, constraints) {
+ pairs[Pair{Param: pn + "=" + v1, Value: pn2 + "=" + v2}] = true
+ }
+ }
+ }
+ }
+ }
+ return pairs
+}
+
+func buildVector(params map[string][]string, paramNames []string, coveredPairs map[Pair]bool, constraints []ConstraintFunc) TestVector {
+ tv := make(TestVector)
+ fillVector(tv, params, paramNames, 0, coveredPairs, constraints)
+ return tv
+}
Review Comment:
buildVector ignores the boolean result of fillVector. As written, buildVector never returns nil, so PairwiseGenerate's `if tv == nil { break }` is dead code and the algorithm can continue with an invalid/partial vector when constraints are unsatisfiable.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add program-generated trace query integration-test framework [skywalking-banyandb]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #1150:
URL: https://github.com/apache/skywalking-banyandb/pull/1150#issuecomment-4599165903
## [Codecov](https://app.codecov.io/gh/apache/skywalking-banyandb/pull/1150?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 41.14%. Comparing base ([`3530dd9`](https://app.codecov.io/gh/apache/skywalking-banyandb/commit/3530dd9b5cefaa4fef60eec91ecbfbdfcaf243c5?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`da60fa0`](https://app.codecov.io/gh/apache/skywalking-banyandb/commit/da60fa0f0a4c2981d7d0dc42c557846c3c80fd51?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 269 commits behind head on main.
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## main #1150 +/- ##
==========================================
- Coverage 45.97% 41.14% -4.83%
==========================================
Files 328 196 -132
Lines 55505 20380 -35125
==========================================
- Hits 25520 8386 -17134
+ Misses 27909 11144 -16765
+ Partials 2076 850 -1226
```
| [Flag](https://app.codecov.io/gh/apache/skywalking-banyandb/pull/1150/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [pkg](https://app.codecov.io/gh/apache/skywalking-banyandb/pull/1150/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `41.14% <ø> (?)` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/skywalking-banyandb/pull/1150?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add program-generated trace query integration-test framework [skywalking-banyandb]
Posted by "hanahmily (via GitHub)" <gi...@apache.org>.
hanahmily commented on code in PR #1150:
URL: https://github.com/apache/skywalking-banyandb/pull/1150#discussion_r3341752245
##########
test/cases/trace/cmd/generate/seed.go:
##########
@@ -0,0 +1,230 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package main
+
+import (
+ "encoding/json"
+ "fmt"
+ "os"
+ "path/filepath"
+ "slices"
+)
+
+// TagType describes a trace tag value type.
+type TagType int
+
+const (
+ TagTypeString TagType = iota
+ TagTypeInt
+ TagTypeTimestamp
+)
+
+// Role describes how generated tests use a tag.
+type Role int
+
+const (
+ RoleIdentity Role = iota
+ RoleIndexed
+ RolePlain
+)
+
+// TagDef describes a trace tag in positional seed order.
+type TagDef struct {
+ Name string
+ Type TagType
+ Pos int
+ Role Role
+}
+
+// SpanRow mirrors one seeded span row used for generation value selection.
+type SpanRow struct {
+ TagValues map[string]any
+ Span string
+}
+
+// Trace describes the trace schema and rows used by generated tests.
+type Trace struct {
+ Name string
+ Group string
+ Groups []string
+ Tags []TagDef
+ OrderRules []string
+ TraceIDTag string
+ SpanIDTag string
+ TimestampTag string
+ Rows []SpanRow
+}
+
+// SeedData returns trace schemas available to the generator.
+func SeedData() []Trace {
+ return []Trace{swTrace()}
+}
+
+// FindTrace returns a trace schema by name.
+func FindTrace(name string) *Trace {
+ for _, traceDef := range SeedData() {
+ if traceDef.Name == name {
+ return &traceDef
+ }
+ }
+ return nil
+}
Review Comment:
Fixed in a555985b: `FindTrace` now indexes the `SeedData()` slice (`return &traces[idx]`) instead of returning the address of the range-loop copy.
##########
test/cases/trace/cmd/generate/pairwise.go:
##########
@@ -0,0 +1,174 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package main
+
+// Copied verbatim from test/cases/measure/cmd/generate/pairwise.go — keep in sync; pure combinatorics, no proto types.
+
+// Pair holds a parameter-value pair for pairwise testing.
+type Pair struct {
+ Param string
+ Value string
+}
+
+// TestVector is a set of parameter-value assignments.
+type TestVector map[string]string
+
+// PairwiseGenerate generates a minimal set of test vectors covering all pairs
+// of parameter values using a simplified IPO (In-Parameter-Order) algorithm.
+func PairwiseGenerate(params map[string][]string, constraints []ConstraintFunc) []TestVector {
+ paramNames := sortedParamNames(params)
+ if len(paramNames) == 0 {
+ return nil
+ }
+
+ // Collect all required pairs
+ requiredPairs := collectAllPairs(params, constraints)
+
+ // Build test vectors using greedy pair covering
+ var vectors []TestVector
+ coveredPairs := make(map[Pair]bool)
+
+ for len(coveredPairs) < len(requiredPairs) {
+ tv := buildVector(params, paramNames, coveredPairs, constraints)
+ if tv == nil {
+ break
+ }
+ // Mark newly covered pairs
+ newCovers := 0
+ for _, pn := range paramNames {
+ for _, pn2 := range paramNames {
+ if pn >= pn2 {
+ continue
+ }
+ p := Pair{Param: pn + "=" + tv[pn], Value: pn2 + "=" + tv[pn2]}
+ if !coveredPairs[p] {
+ coveredPairs[p] = true
+ newCovers++
+ }
+ }
+ }
+ if newCovers == 0 {
+ break
+ }
+ vectors = append(vectors, tv)
+ }
+ return vectors
+}
+
+// ConstraintFunc returns false if the combination is invalid.
+type ConstraintFunc func(tv TestVector) bool
+
+func collectAllPairs(params map[string][]string, constraints []ConstraintFunc) map[Pair]bool {
+ pairs := make(map[Pair]bool)
+ paramNames := sortedParamNames(params)
+ for _, pn := range paramNames {
+ for _, pn2 := range paramNames {
+ if pn >= pn2 {
+ continue
+ }
+ for _, v1 := range params[pn] {
+ for _, v2 := range params[pn2] {
+ tv := TestVector{pn: v1, pn2: v2}
+ if validConstraints(tv, constraints) {
+ pairs[Pair{Param: pn + "=" + v1, Value: pn2 + "=" + v2}] = true
+ }
+ }
+ }
+ }
+ }
+ return pairs
+}
+
+func buildVector(params map[string][]string, paramNames []string, coveredPairs map[Pair]bool, constraints []ConstraintFunc) TestVector {
+ tv := make(TestVector)
+ fillVector(tv, params, paramNames, 0, coveredPairs, constraints)
+ return tv
+}
Review Comment:
Fixed in a555985b: `buildVector` now returns nil when `fillVector` reports no constraint-satisfying assignment, so `PairwiseGenerate`'s `if tv == nil { break }` is live and the algorithm no longer records a partial/invalid vector.
##########
test/cases/trace/cmd/generate/pairwise.go:
##########
@@ -0,0 +1,174 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package main
+
+// Copied verbatim from test/cases/measure/cmd/generate/pairwise.go — keep in sync; pure combinatorics, no proto types.
+
+// Pair holds a parameter-value pair for pairwise testing.
+type Pair struct {
+ Param string
+ Value string
+}
+
+// TestVector is a set of parameter-value assignments.
+type TestVector map[string]string
+
+// PairwiseGenerate generates a minimal set of test vectors covering all pairs
+// of parameter values using a simplified IPO (In-Parameter-Order) algorithm.
+func PairwiseGenerate(params map[string][]string, constraints []ConstraintFunc) []TestVector {
+ paramNames := sortedParamNames(params)
+ if len(paramNames) == 0 {
+ return nil
+ }
+
+ // Collect all required pairs
+ requiredPairs := collectAllPairs(params, constraints)
+
+ // Build test vectors using greedy pair covering
+ var vectors []TestVector
+ coveredPairs := make(map[Pair]bool)
+
+ for len(coveredPairs) < len(requiredPairs) {
+ tv := buildVector(params, paramNames, coveredPairs, constraints)
+ if tv == nil {
+ break
+ }
+ // Mark newly covered pairs
+ newCovers := 0
+ for _, pn := range paramNames {
+ for _, pn2 := range paramNames {
+ if pn >= pn2 {
+ continue
+ }
+ p := Pair{Param: pn + "=" + tv[pn], Value: pn2 + "=" + tv[pn2]}
+ if !coveredPairs[p] {
+ coveredPairs[p] = true
+ newCovers++
+ }
+ }
+ }
+ if newCovers == 0 {
+ break
+ }
+ vectors = append(vectors, tv)
+ }
+ return vectors
+}
+
+// ConstraintFunc returns false if the combination is invalid.
+type ConstraintFunc func(tv TestVector) bool
+
+func collectAllPairs(params map[string][]string, constraints []ConstraintFunc) map[Pair]bool {
+ pairs := make(map[Pair]bool)
+ paramNames := sortedParamNames(params)
+ for _, pn := range paramNames {
+ for _, pn2 := range paramNames {
+ if pn >= pn2 {
+ continue
+ }
+ for _, v1 := range params[pn] {
+ for _, v2 := range params[pn2] {
+ tv := TestVector{pn: v1, pn2: v2}
+ if validConstraints(tv, constraints) {
+ pairs[Pair{Param: pn + "=" + v1, Value: pn2 + "=" + v2}] = true
+ }
+ }
+ }
+ }
+ }
+ return pairs
+}
+
+func buildVector(params map[string][]string, paramNames []string, coveredPairs map[Pair]bool, constraints []ConstraintFunc) TestVector {
+ tv := make(TestVector)
+ fillVector(tv, params, paramNames, 0, coveredPairs, constraints)
+ return tv
+}
+
+func fillVector(tv TestVector, params map[string][]string, paramNames []string, paramIdx int, coveredPairs map[Pair]bool, constraints []ConstraintFunc) bool {
+ if paramIdx >= len(paramNames) {
+ return validConstraints(tv, constraints)
+ }
+ pn := paramNames[paramIdx]
+ bestVal := ""
+ bestScore := -1
+ for _, val := range params[pn] {
+ tv[pn] = val
+ if !validConstraints(tv, constraints) {
+ continue
+ }
+ score := countNewPairs(tv, paramNames, paramIdx, coveredPairs)
+ if score > bestScore {
+ bestScore = score
+ bestVal = val
+ }
+ }
+ if bestVal == "" {
+ // Fallback: pick first valid value
+ for _, val := range params[pn] {
+ tv[pn] = val
+ if validConstraints(tv, constraints) {
+ bestVal = val
+ break
+ }
+ }
+ if bestVal == "" {
+ tv[pn] = params[pn][0]
+ }
+ }
+ tv[pn] = bestVal
+ return fillVector(tv, params, paramNames, paramIdx+1, coveredPairs, constraints)
Review Comment:
Fixed in a555985b: the last-resort fallback now assigns `bestVal = params[pn][0]` (instead of `tv[pn] = ...`), so the trailing `tv[pn] = bestVal` no longer overwrites it with the empty string.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add program-generated trace query integration-test framework [skywalking-banyandb]
Posted by "hanahmily (via GitHub)" <gi...@apache.org>.
hanahmily merged PR #1150:
URL: https://github.com/apache/skywalking-banyandb/pull/1150
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org