Skip to content

Commit 807aa90

Browse files
committed
roachtest: support test name variation suffixes in perturbation framework
Add an optional perturbationNamer interface a perturbation may implement to append a variation suffix to its test name. With this a single struct type can register multiple test entries that differ in configuration; a later commit uses it to register the splits test in two flavors (followers asleep vs. forced awake) under distinct names like perturbation/full/splits/asleep=true perturbation/full/splits/asleep=false without resorting to one struct per variant. No behavior change for existing perturbations — none of them implement the interface, so perturbationName() falls through to the reflection-based type name as before. Epic: none Release note: None
1 parent ef76e92 commit 807aa90

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

pkg/cmd/roachtest/tests/perturbation/framework.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,14 @@ func (v variations) perturbationName() string {
445445
if t.Kind() == reflect.Ptr {
446446
t = t.Elem()
447447
}
448-
return t.Name()
448+
name := t.Name()
449+
// Allow a perturbation to append a variation suffix (e.g. "/asleep=true")
450+
// so the same struct type can register multiple test entries that differ
451+
// in configuration. See perturbationNamer.
452+
if namer, ok := v.perturbation.(perturbationNamer); ok {
453+
name += namer.nameSuffix()
454+
}
455+
return name
449456
}
450457

451458
// finishSetup completes initialization of the variations.
@@ -724,6 +731,19 @@ type perturbation interface {
724731
endPerturbation(ctx context.Context, t test.Test, v variations) time.Duration
725732
}
726733

734+
// perturbationNamer is an optional interface a perturbation may implement to
735+
// append a variation suffix to its test name. For example, a perturbation
736+
// that registers two flavors of the same struct can return "/asleep=true"
737+
// and "/asleep=false" to produce distinct test names like
738+
// "perturbation/full/splits/asleep=true".
739+
//
740+
// Implementations should return either an empty string (no suffix) or a
741+
// string starting with "/" so the test name reads naturally when composed
742+
// with the parent path.
743+
type perturbationNamer interface {
744+
nameSuffix() string
745+
}
746+
727747
func prettyPrint(title string, stats map[string]aggregatedStat) string {
728748
var outputStr strings.Builder
729749
outputStr.WriteString(title + "\n")

0 commit comments

Comments
 (0)