Skip to content

Commit 23ae0dd

Browse files
committed
metamorphic: fix key format when running a single config
`RunOnce` takes the `KeyFormat` separately, but the one we pass is derived from the flags, not the one that is passed to us from e.g. `TestMetaCockroachKVs`. This change fixes this. Note that when running the test normally, the top-level process passes `--key-format` to the child process, so in that case it works out.
1 parent 6d1e29e commit 23ae0dd

File tree

4 files changed

+9
-15
lines changed

4 files changed

+9
-15
lines changed

internal/metamorphic/meta_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ func runTestMeta(t *testing.T, addtlOptions ...option) {
7979
tryToReduceCompare(t, runOnceFlags.Dir, testRootDir, runSubdirs, runOnceFlags.ReduceAttempts)
8080
return
8181
}
82-
metamorphic.Compare(t, testRootDir, runOnceFlags.Seed, runSubdirs,
83-
runOnceFlags.KeyFormat(), onceOpts...)
82+
metamorphic.Compare(t, testRootDir, runOnceFlags.Seed, runSubdirs, onceOpts...)
8483

8584
case runOnceFlags.RunDir != "":
8685
// The --run-dir flag is specified either in the child process (see
@@ -95,7 +94,7 @@ func runTestMeta(t *testing.T, addtlOptions ...option) {
9594
return
9695
}
9796
metamorphic.RunOnce(t, runOnceFlags.RunDir, runOnceFlags.Seed,
98-
filepath.Join(runOnceFlags.RunDir, "history"), runOnceFlags.KeyFormat(), onceOpts...)
97+
filepath.Join(runOnceFlags.RunDir, "history"), onceOpts...)
9998

10099
default:
101100
opts := runFlags.MakeRunOptions()

internal/metamorphic/metaflags/meta_flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ func (ro *RunOnceFlags) MakeRunOnceOptions() []metamorphic.RunOnceOption {
230230
onceOpts := []metamorphic.RunOnceOption{
231231
metamorphic.MaxThreads(ro.MaxThreads),
232232
metamorphic.OpTimeout(ro.OpTimeout),
233+
ro.KeyFormat(),
233234
}
234235
if ro.Keep {
235236
onceOpts = append(onceOpts, metamorphic.KeepData{})

internal/metamorphic/metarunner/main.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,14 @@ func main() {
2727
switch {
2828
case runOnceFlags.Compare != "":
2929
testRootDir, runSubdirs := runOnceFlags.ParseCompare()
30-
metamorphic.Compare(t, testRootDir, runOnceFlags.Seed, runSubdirs,
31-
runOnceFlags.KeyFormat(), onceOpts...)
30+
metamorphic.Compare(t, testRootDir, runOnceFlags.Seed, runSubdirs, onceOpts...)
3231

3332
case runOnceFlags.RunDir != "":
3433
// The --run-dir flag is specified either in the child process (see
3534
// runOptions() below) or the user specified it manually in order to re-run
3635
// a test.
3736
metamorphic.RunOnce(t, runOnceFlags.RunDir, runOnceFlags.Seed,
38-
filepath.Join(runOnceFlags.RunDir, "history"),
39-
runOnceFlags.KeyFormat(), onceOpts...)
37+
filepath.Join(runOnceFlags.RunDir, "history"), onceOpts...)
4038

4139
default:
4240
t.Errorf("--compare or --run-dir must be used")

metamorphic/meta.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,7 @@ func (m MultiInstance) applyOnce(ro *runOnceOptions) { ro.numInstances = int(m
462462
// to a file at the path `historyPath`.
463463
//
464464
// The `seed` parameter is not functional; it's used for context in logging.
465-
func RunOnce(
466-
t TestingT, runDir string, seed uint64, historyPath string, kf KeyFormat, rOpts ...RunOnceOption,
467-
) {
465+
func RunOnce(t TestingT, runDir string, seed uint64, historyPath string, rOpts ...RunOnceOption) {
468466
runOpts := runOnceOptions{
469467
customOptionParsers: map[string]func(string) (CustomOption, bool){},
470468
}
@@ -483,7 +481,7 @@ func RunOnce(
483481
// NB: It's important to use defaultTestOptions() here as the base into
484482
// which we parse the serialized options. It contains the relevant defaults,
485483
// like the appropriate block-property collectors.
486-
testOpts := defaultTestOptions(kf)
484+
testOpts := defaultTestOptions(runOpts.keyFormat)
487485
opts := testOpts.Opts
488486
require.NoError(t, parseOptions(testOpts, string(optionsData), runOpts.customOptionParsers))
489487

@@ -662,9 +660,7 @@ func hashThread(objID objID, numThreads int) int {
662660

663661
// Compare runs the metamorphic tests in the provided runDirs and compares their
664662
// histories.
665-
func Compare(
666-
t TestingT, rootDir string, seed uint64, runDirs []string, kf KeyFormat, rOpts ...RunOnceOption,
667-
) {
663+
func Compare(t TestingT, rootDir string, seed uint64, runDirs []string, rOpts ...RunOnceOption) {
668664
historyPaths := make([]string, len(runDirs))
669665
for i := 0; i < len(runDirs); i++ {
670666
historyPath := filepath.Join(rootDir, runDirs[i]+"-"+time.Now().Format("060102-150405.000"))
@@ -679,7 +675,7 @@ func Compare(
679675
}()
680676

681677
for i, runDir := range runDirs {
682-
RunOnce(t, runDir, seed, historyPaths[i], kf, rOpts...)
678+
RunOnce(t, runDir, seed, historyPaths[i], rOpts...)
683679
}
684680

685681
if t.Failed() {

0 commit comments

Comments
 (0)