Skip to content

Commit 361b7f9

Browse files
committed
type tree preparation for persistence
1 parent 970e151 commit 361b7f9

6 files changed

Lines changed: 25 additions & 15 deletions

File tree

pkg/coordinator/coordinator.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type Coordinator struct {
5252
testDescriptorIndex uint64
5353

5454
testRunMap map[uint64]types.Test
55-
testQueue []types.Test
55+
testQueue []types.TestRunner
5656
testHistory []types.Test
5757
testRegistryMutex sync.RWMutex
5858
testNotificationChan chan bool
@@ -75,7 +75,7 @@ func NewCoordinator(config *Config, log logrus.FieldLogger, metricsPort int) *Co
7575

7676
testDescriptors: map[string]testDescriptorEntry{},
7777
testRunMap: map[uint64]types.Test{},
78-
testQueue: []types.Test{},
78+
testQueue: []types.TestRunner{},
7979
testHistory: []types.Test{},
8080
testNotificationChan: make(chan bool, 1),
8181
}
@@ -328,7 +328,9 @@ func (c *Coordinator) GetTestQueue() []types.Test {
328328
defer c.testRegistryMutex.RUnlock()
329329

330330
tests := make([]types.Test, len(c.testQueue))
331-
copy(tests, c.testQueue)
331+
for idx, test := range c.testQueue {
332+
tests[idx] = test
333+
}
332334

333335
return tests
334336
}
@@ -355,7 +357,7 @@ func (c *Coordinator) startMetrics() error {
355357
return err
356358
}
357359

358-
func (c *Coordinator) ScheduleTest(descriptor types.TestDescriptor, configOverrides map[string]any, allowDuplicate bool) (types.Test, error) {
360+
func (c *Coordinator) ScheduleTest(descriptor types.TestDescriptor, configOverrides map[string]any, allowDuplicate bool) (types.TestRunner, error) {
359361
if descriptor.Err() != nil {
360362
return nil, fmt.Errorf("cannot create test from failed test descriptor: %w", descriptor.Err())
361363
}
@@ -373,7 +375,7 @@ func (c *Coordinator) ScheduleTest(descriptor types.TestDescriptor, configOverri
373375
return testRef, nil
374376
}
375377

376-
func (c *Coordinator) createTestRun(descriptor types.TestDescriptor, configOverrides map[string]any, allowDuplicate bool) (types.Test, error) {
378+
func (c *Coordinator) createTestRun(descriptor types.TestDescriptor, configOverrides map[string]any, allowDuplicate bool) (types.TestRunner, error) {
377379
c.testSchedulerMutex.Lock()
378380
defer c.testSchedulerMutex.Unlock()
379381

@@ -417,7 +419,7 @@ func (c *Coordinator) runTestExecutionLoop(ctx context.Context) {
417419
semaphore := make(chan bool, concurrencyLimit)
418420

419421
for {
420-
var nextTest types.Test
422+
var nextTest types.TestRunner
421423

422424
c.testRegistryMutex.Lock()
423425
if len(c.testQueue) > 0 {
@@ -429,7 +431,7 @@ func (c *Coordinator) runTestExecutionLoop(ctx context.Context) {
429431

430432
if nextTest != nil {
431433
// run next test
432-
testFunc := func(nextTest types.Test) {
434+
testFunc := func(nextTest types.TestRunner) {
433435
defer func() { <-semaphore }()
434436
c.runTest(ctx, nextTest)
435437
}
@@ -448,7 +450,7 @@ func (c *Coordinator) runTestExecutionLoop(ctx context.Context) {
448450
}
449451
}
450452

451-
func (c *Coordinator) runTest(ctx context.Context, testRef types.Test) {
453+
func (c *Coordinator) runTest(ctx context.Context, testRef types.TestRunner) {
452454
c.lastExecutedRunID = testRef.RunID()
453455

454456
if err := testRef.Validate(); err != nil {

pkg/coordinator/test/test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type Test struct {
2525
timeout time.Duration
2626
}
2727

28-
func CreateTest(runID uint64, descriptor types.TestDescriptor, logger logrus.FieldLogger, services types.TaskServices) (types.Test, error) {
28+
func CreateTest(runID uint64, descriptor types.TestDescriptor, logger logrus.FieldLogger, services types.TaskServices) (types.TestRunner, error) {
2929
test := &Test{
3030
runID: runID,
3131
logger: logger.WithField("RunID", runID).WithField("TestID", descriptor.ID()),

pkg/coordinator/types/coordinator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ type Coordinator interface {
2626
GetTestByRunID(runID uint64) Test
2727
GetTestQueue() []Test
2828
GetTestHistory() []Test
29-
ScheduleTest(descriptor TestDescriptor, configOverrides map[string]any, allowDuplicate bool) (Test, error)
29+
ScheduleTest(descriptor TestDescriptor, configOverrides map[string]any, allowDuplicate bool) (TestRunner, error)
3030
}

pkg/coordinator/types/scheduler.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ import (
99
"github.com/ethpandaops/assertoor/pkg/coordinator/wallet"
1010
)
1111

12-
type TaskScheduler interface {
12+
type TaskSchedulerRunner interface {
13+
TaskScheduler
1314
GetServices() TaskServices
1415
ParseTaskOptions(rawtask *helper.RawMessage) (*TaskOptions, error)
1516
ExecuteTask(ctx context.Context, taskIndex TaskIndex, taskWatchFn func(ctx context.Context, cancelFn context.CancelFunc, taskIndex TaskIndex)) error
1617
WatchTaskPass(ctx context.Context, cancelFn context.CancelFunc, taskIndex TaskIndex)
18+
}
19+
20+
type TaskScheduler interface {
1721
GetTaskState(taskIndex TaskIndex) TaskState
1822
GetTaskCount() int
1923
GetAllTasks() []TaskIndex

pkg/coordinator/types/task.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ type TaskStatus struct {
7979
}
8080

8181
type TaskContext struct {
82-
Scheduler TaskScheduler
82+
Scheduler TaskSchedulerRunner
8383
Index TaskIndex
8484
Vars Variables
8585
Outputs Variables

pkg/coordinator/types/test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ const (
1919
TestStatusAborted TestStatus = "aborted"
2020
)
2121

22-
type Test interface {
22+
type TestRunner interface {
23+
Test
2324
Validate() error
2425
Run(ctx context.Context) error
26+
GetTestVariables() Variables
27+
}
28+
29+
type Test interface {
2530
RunID() uint64
2631
TestID() string
2732
Name() string
@@ -31,9 +36,8 @@ type Test interface {
3136
Percent() float64
3237
Status() TestStatus
3338
Logger() logrus.FieldLogger
34-
AbortTest(skipCleanup bool)
3539
GetTaskScheduler() TaskScheduler
36-
GetTestVariables() Variables
40+
AbortTest(skipCleanup bool)
3741
}
3842

3943
type TestConfig struct {

0 commit comments

Comments
 (0)