Skip to content

Commit ac01b42

Browse files
committed
metamorphic: support --initial-state with --run/compare
Allow supplying an initial state when trying to reproduce a failure.
1 parent 433156b commit ac01b42

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

internal/metamorphic/metaflags/meta_flags.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ type CommonFlags struct {
4949
// KeyFormatName is the name of the KeyFormat to use. Defaults to "testkeys".
5050
// Acceptable values are "testkeys" and "cockroachkvs".
5151
KeyFormatName string
52+
// InitialStatePath is the path to a database data directory from a previous
53+
// run. See the "initial-state" flag below.
54+
InitialStatePath string
5255
}
5356

5457
// KeyFormat returns the KeyFormat indicated by the flags KeyFormatName.
@@ -105,6 +108,10 @@ func initCommonFlags() *CommonFlags {
105108
flag.StringVar(&c.KeyFormatName, "key-format", "testkeys",
106109
"name of the key format to use")
107110

111+
flag.StringVar(&c.InitialStatePath, "initial-state", "",
112+
`path to a database's data directory, used to prepopulate the test run's databases.
113+
Must be used in conjunction with --previous-ops (unless --run or --compare is used).`)
114+
108115
return c
109116
}
110117

@@ -161,9 +168,6 @@ type RunFlags struct {
161168
// PreviousOps is the path to the ops file of a previous run. See the
162169
// "previous-ops" flag below.
163170
PreviousOps string
164-
// InitialStatePath is the path to a database data directory from a previous
165-
// run. See the "initial-state" flag below.
166-
InitialStatePath string
167171
// InitialStateDesc is a human-readable description of the initial database
168172
// state. See "initial-state-desc" flag below.
169173
InitialStateDesc string
@@ -202,10 +206,6 @@ with --run-dir or --compare`)
202206
`path to an ops file, used to prepopulate the set of keys operations draw from." +
203207
Must be used in conjunction with --initial-state`)
204208

205-
flag.StringVar(&r.InitialStatePath, "initial-state", "",
206-
`path to a database's data directory, used to prepopulate the test run's databases.
207-
Must be used in conjunction with --previous-ops.`)
208-
209209
flag.StringVar(&r.InitialStateDesc, "initial-state-desc", "",
210210
`a human-readable description of the initial database state.
211211
If set this parameter is written to the OPTIONS to aid in
@@ -247,6 +247,9 @@ func (ro *RunOnceFlags) MakeRunOnceOptions() []metamorphic.RunOnceOption {
247247
if ro.NumInstances > 1 {
248248
onceOpts = append(onceOpts, metamorphic.MultiInstance(ro.NumInstances))
249249
}
250+
if ro.InitialStatePath != "" {
251+
onceOpts = append(onceOpts, metamorphic.RunOnceInitialStatePath(ro.InitialStatePath))
252+
}
250253
return onceOpts
251254
}
252255

metamorphic/meta.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ type runOnceOptions struct {
409409
failRegexp *regexp.Regexp
410410
numInstances int
411411
keyFormat KeyFormat
412+
initialStatePath string
412413
customOptionParsers map[string]func(string) (CustomOption, bool)
413414
}
414415

@@ -462,6 +463,12 @@ type MultiInstance int
462463
func (m MultiInstance) apply(ro *runAndCompareOptions) { ro.numInstances = int(m) }
463464
func (m MultiInstance) applyOnce(ro *runOnceOptions) { ro.numInstances = int(m) }
464465

466+
// RunOnceInitialStatePath is used to set an initial database state path for a
467+
// single run.
468+
type RunOnceInitialStatePath string
469+
470+
func (i RunOnceInitialStatePath) applyOnce(ro *runOnceOptions) { ro.initialStatePath = string(i) }
471+
465472
// RunOnce performs one run of the metamorphic tests. RunOnce expects the
466473
// directory named by `runDir` to already exist and contain an `OPTIONS` file
467474
// containing the test run's configuration. The history of the run is persisted
@@ -491,6 +498,10 @@ func RunOnce(t TestingT, runDir string, seed uint64, historyPath string, rOpts .
491498
opts := testOpts.Opts
492499
require.NoError(t, parseOptions(testOpts, string(optionsData), runOpts.customOptionParsers))
493500

501+
if runOpts.initialStatePath != "" {
502+
testOpts.initialStatePath = runOpts.initialStatePath
503+
}
504+
494505
ops, err := parse(opsData, parserOpts{
495506
parseFormattedUserKey: testOpts.KeyFormat.ParseFormattedKey,
496507
parseFormattedUserKeySuffix: testOpts.KeyFormat.ParseFormattedKeySuffix,

0 commit comments

Comments
 (0)