Skip to content

Commit

Permalink
roachtest: add groups to test framework
Browse files Browse the repository at this point in the history
This change groups the default options used by tasks and groups into a function
that can be shared when creating new groups or tasks via the test framework. The
`Test` interface now implements `GroupProvider` as well to enable grouping
tasks.

Informs: cockroachdb#118214

Epic: None
Release note: None
  • Loading branch information
herkolategan committed Dec 11, 2024
1 parent 6c69685 commit 97578e0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pkg/cmd/roachtest/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ func (t testWrapper) Go(_ task.Func, _ ...task.Option) {
panic("implement me")
}

func (t testWrapper) NewGroup() task.Group {
panic("implement me")
}

var _ test2.Test = testWrapper{}

// ArtifactsDir is part of the test.Test interface.
Expand Down
14 changes: 14 additions & 0 deletions pkg/cmd/roachtest/clusterstats/mock_test_generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/cmd/roachtest/test/test_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type Test interface {

Go(task.Func, ...task.Option)
GoWithCancel(task.Func, ...task.Option) context.CancelFunc
NewGroup() task.Group

// DeprecatedWorkload returns the path to the workload binary.
// Don't use this, invoke `./cockroach workload` instead.
Expand Down
18 changes: 15 additions & 3 deletions pkg/cmd/roachtest/test_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,21 +688,33 @@ func (t *testImpl) IsBuildVersion(minVersion string) bool {
return t.BuildVersion().AtLeast(vers)
}

func panicHandler(_ context.Context, name string, l *logger.Logger, r interface{}) error {
return fmt.Errorf("test task %s panicked: %v", name, r)
// defaultTaskOptions returns the default options for a task started by the test.
func defaultTaskOptions() []task.Option {
return []task.Option{
task.PanicHandler(func(_ context.Context, name string, l *logger.Logger, r interface{}) error {
return fmt.Errorf("test task %s panicked: %v", name, r)
}),
}
}

// GoWithCancel runs the given function in a goroutine and returns a
// CancelFunc that can be used to cancel the function.
func (t *testImpl) GoWithCancel(fn task.Func, opts ...task.Option) context.CancelFunc {
return t.taskManager.GoWithCancel(fn, task.PanicHandler(panicHandler), task.OptionList(opts...))
return t.taskManager.GoWithCancel(
fn, task.OptionList(defaultTaskOptions()...), task.OptionList(opts...),
)
}

// Go is like GoWithCancel but without a cancel function.
func (t *testImpl) Go(fn task.Func, opts ...task.Option) {
_ = t.GoWithCancel(fn, task.OptionList(opts...))
}

// NewGroup starts a new task group.
func (t *testImpl) NewGroup() task.Group {
return t.taskManager.NewGroup(defaultTaskOptions()...)
}

// TeamCityEscape escapes a string for use as <value> in a key='<value>' attribute
// in TeamCity build output marker.
// See https://www.jetbrains.com/help/teamcity/2023.05/service-messages.html#Escaped+Values
Expand Down

0 comments on commit 97578e0

Please sign in to comment.