Skip to content

Commit 3cf2d5f

Browse files
authored
feat: allow specifying test data dirs (#132)
1 parent cac437f commit 3cf2d5f

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

runner/benchmark/definition.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,15 @@ type BenchmarkConfig struct {
9191
TransactionPayloads []payload.Definition `yaml:"payloads"`
9292
}
9393

94+
type DatadirConfig struct {
95+
Sequencer *string `yaml:"sequencer"`
96+
Validator *string `yaml:"validator"`
97+
}
98+
9499
// TestDefinition is the user-facing YAML configuration for specifying a
95100
// matrix of benchmark runs.
96101
type TestDefinition struct {
102+
Datadir *DatadirConfig `yaml:"datadirs"`
97103
Snapshot *SnapshotDefinition `yaml:"snapshot"`
98104
Metrics *ThresholdConfig `yaml:"metrics"`
99105
Tags *map[string]string `yaml:"tags"`

runner/benchmark/matrix.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type ThresholdConfig struct {
1313
// TestPlan represents a list of test runs to be executed.
1414
type TestPlan struct {
1515
Runs []TestRun
16+
Datadir *DatadirConfig
1617
Snapshot *SnapshotDefinition
1718
ProofProgram *ProofProgramOptions
1819
Thresholds *ThresholdConfig
@@ -37,6 +38,7 @@ func NewTestPlanFromConfig(c TestDefinition, testFileName string, config *Benchm
3738

3839
return &TestPlan{
3940
Runs: testRuns,
41+
Datadir: c.Datadir,
4042
Snapshot: c.Snapshot,
4143
ProofProgram: proofProgram,
4244
Thresholds: c.Metrics,

runner/benchmark/snapshots.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type SnapshotManager interface {
1212
// EnsureSnapshot ensures that a snapshot exists for the given node type and
1313
// role. If it does not exist, it will create it using the given snapshot
1414
// definition. It returns the path to the snapshot.
15-
EnsureSnapshot(definition SnapshotDefinition, nodeType string, role string) (string, error)
15+
EnsureSnapshot(datadirsConfig *DatadirConfig, definition SnapshotDefinition, nodeType string, role string) (string, error)
1616
}
1717

1818
type snapshotStoragePath struct {
@@ -58,7 +58,7 @@ func NewSnapshotManager(snapshotsDir string) SnapshotManager {
5858
}
5959
}
6060

61-
func (b *benchmarkDatadirState) EnsureSnapshot(definition SnapshotDefinition, nodeType string, role string) (string, error) {
61+
func (b *benchmarkDatadirState) EnsureSnapshot(datadirsConfig *DatadirConfig, definition SnapshotDefinition, nodeType string, role string) (string, error) {
6262
snapshotDatadir := snapshotStoragePath{
6363
nodeType: nodeType,
6464
role: role,
@@ -69,10 +69,15 @@ func (b *benchmarkDatadirState) EnsureSnapshot(definition SnapshotDefinition, no
6969
return datadir, nil
7070
}
7171

72-
hashCommand := sha256.New().Sum([]byte(definition.Command))
73-
74-
snapshotPath := filepath.Join(b.snapshotsDir, fmt.Sprintf("%s_%s_%x", nodeType, role, hashCommand[:12]))
75-
72+
var snapshotPath string
73+
if datadirsConfig != nil && role == "validator" && datadirsConfig.Validator != nil {
74+
snapshotPath = *datadirsConfig.Validator
75+
} else if datadirsConfig != nil && role == "sequencer" && datadirsConfig.Sequencer != nil {
76+
snapshotPath = *datadirsConfig.Sequencer
77+
} else {
78+
hashCommand := sha256.New().Sum([]byte(definition.Command))
79+
snapshotPath = filepath.Join(b.snapshotsDir, fmt.Sprintf("%s_%s_%x", nodeType, role, hashCommand[:12]))
80+
}
7681
// Create a new datadir for this snapshot.
7782
err := definition.CreateSnapshot(nodeType, snapshotPath)
7883
if err != nil {

runner/service.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func readBenchmarkConfig(path string) (*benchmark.BenchmarkConfig, error) {
7373
return config, err
7474
}
7575

76-
func (s *service) setupInternalDirectories(testDir string, params types.RunParams, genesis *core.Genesis, snapshot *benchmark.SnapshotDefinition, role string) (*config.InternalClientOptions, error) {
76+
func (s *service) setupInternalDirectories(testDir string, params types.RunParams, genesis *core.Genesis, snapshot *benchmark.SnapshotDefinition, role string, datadirsConfig *benchmark.DatadirConfig) (*config.InternalClientOptions, error) {
7777
err := os.MkdirAll(testDir, 0755)
7878
if err != nil {
7979
return nil, errors.Wrap(err, "failed to create test directory")
@@ -102,7 +102,7 @@ func (s *service) setupInternalDirectories(testDir string, params types.RunParam
102102
isSnapshot := snapshot != nil && snapshot.Command != ""
103103
if isSnapshot {
104104
// if we have a snapshot, restore it if needed or reuse from a previous test
105-
snapshotDir, err := s.dataDirState.EnsureSnapshot(*snapshot, params.NodeType, role)
105+
snapshotDir, err := s.dataDirState.EnsureSnapshot(datadirsConfig, *snapshot, params.NodeType, role)
106106
if err != nil {
107107
return nil, errors.Wrap(err, "failed to ensure snapshot")
108108
}
@@ -291,18 +291,18 @@ func (s *service) getGenesisForSnapshotConfig(snapshotConfig *benchmark.Snapshot
291291
return genesis, nil
292292
}
293293

294-
func (s *service) setupDataDirs(workingDir string, params types.RunParams, genesis *core.Genesis, snapshot *benchmark.SnapshotDefinition) (*config.InternalClientOptions, *config.InternalClientOptions, error) {
294+
func (s *service) setupDataDirs(workingDir string, params types.RunParams, genesis *core.Genesis, snapshot *benchmark.SnapshotDefinition, datadirsConfig *benchmark.DatadirConfig) (*config.InternalClientOptions, *config.InternalClientOptions, error) {
295295
// create temp directory for this test
296296
testName := fmt.Sprintf("%d-%s-test", time.Now().Unix(), params.NodeType)
297297
sequencerTestDir := path.Join(workingDir, fmt.Sprintf("%s-sequencer", testName))
298298
validatorTestDir := path.Join(workingDir, fmt.Sprintf("%s-validator", testName))
299299

300-
sequencerOptions, err := s.setupInternalDirectories(sequencerTestDir, params, genesis, snapshot, "sequencer")
300+
sequencerOptions, err := s.setupInternalDirectories(sequencerTestDir, params, genesis, snapshot, "sequencer", datadirsConfig)
301301
if err != nil {
302302
return nil, nil, errors.Wrap(err, "failed to setup internal directories")
303303
}
304304

305-
validatorOptions, err := s.setupInternalDirectories(validatorTestDir, params, genesis, snapshot, "validator")
305+
validatorOptions, err := s.setupInternalDirectories(validatorTestDir, params, genesis, snapshot, "validator", datadirsConfig)
306306
if err != nil {
307307
return nil, nil, errors.Wrap(err, "failed to setup internal directories")
308308
}
@@ -320,7 +320,7 @@ func (s *service) setupBlobsDir(workingDir string) error {
320320
return nil
321321
}
322322

323-
func (s *service) runTest(ctx context.Context, params types.RunParams, workingDir string, outputDir string, snapshotConfig *benchmark.SnapshotDefinition, proofConfig *benchmark.ProofProgramOptions, transactionPayload payload.Definition) (*benchmark.RunResult, error) {
323+
func (s *service) runTest(ctx context.Context, params types.RunParams, workingDir string, outputDir string, snapshotConfig *benchmark.SnapshotDefinition, proofConfig *benchmark.ProofProgramOptions, transactionPayload payload.Definition, datadirsConfig *benchmark.DatadirConfig) (*benchmark.RunResult, error) {
324324

325325
s.log.Info(fmt.Sprintf("Running benchmark with params: %+v", params))
326326

@@ -336,7 +336,7 @@ func (s *service) runTest(ctx context.Context, params types.RunParams, workingDi
336336
validatorTestDir := path.Join(workingDir, fmt.Sprintf("%s-validator", testName))
337337

338338
// setup data directories (restore from snapshot if needed)
339-
sequencerOptions, validatorOptions, err := s.setupDataDirs(workingDir, params, genesis, snapshotConfig)
339+
sequencerOptions, validatorOptions, err := s.setupDataDirs(workingDir, params, genesis, snapshotConfig, datadirsConfig)
340340
if err != nil {
341341
return nil, errors.Wrap(err, "failed to setup data dirs")
342342
}
@@ -566,7 +566,7 @@ outerLoop:
566566
return errors.Wrap(err, "failed to create output directory")
567567
}
568568

569-
metricSummary, err := s.runTest(ctx, c.Params, s.config.DataDir(), outputDir, testPlan.Snapshot, testPlan.ProofProgram, transactionPayloads[c.Params.PayloadID])
569+
metricSummary, err := s.runTest(ctx, c.Params, s.config.DataDir(), outputDir, testPlan.Snapshot, testPlan.ProofProgram, transactionPayloads[c.Params.PayloadID], testPlan.Datadir)
570570
if err != nil {
571571
log.Error("Failed to run test", "err", err)
572572
metricSummary = &benchmark.RunResult{

0 commit comments

Comments
 (0)