Skip to content

Commit

Permalink
Allow overriding the test parallelism. (#593)
Browse files Browse the repository at this point in the history
* Allow overriding the test parallelism.

* Add comment for confusing default
  • Loading branch information
jbarrick-mesosphere committed Jul 19, 2019
1 parent cb22b76 commit 0bb97d3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions kudo-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ testDirs:
- ./test/integration
startKUDO: true
startControlPlane: true
parallel: 4
2 changes: 2 additions & 0 deletions pkg/apis/kudo/v1alpha1/test_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type TestSuite struct {
SkipClusterDelete bool `json:"skipClusterDelete"`
// Override the default timeout of 30 seconds (in seconds).
Timeout int `json:"timeout"`
// The maximum number of tests to run at once (default: 8).
Parallel int `json:"parallel"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
9 changes: 8 additions & 1 deletion pkg/kudoctl/cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func newTestCmd() *cobra.Command {
startKUDO := false
skipDelete := false
skipClusterDelete := false
parallel := 0

options := kudo.TestSuite{}

Expand Down Expand Up @@ -141,6 +142,10 @@ For more detailed documentation, visit: https://kudo.dev/docs/testing`,
options.SkipClusterDelete = skipClusterDelete
}

if isSet(flags, "parallel") {
options.Parallel = parallel
}

if len(args) != 0 {
options.TestDirs = args
}
Expand All @@ -152,7 +157,7 @@ For more detailed documentation, visit: https://kudo.dev/docs/testing`,
return nil
},
Run: func(cmd *cobra.Command, args []string) {
testutils.RunTests("kudo", testToRun, func(t *testing.T) {
testutils.RunTests("kudo", testToRun, options.Parallel, func(t *testing.T) {
harness := test.Harness{
TestSuite: options,
T: t,
Expand All @@ -174,6 +179,8 @@ For more detailed documentation, visit: https://kudo.dev/docs/testing`,
testCmd.Flags().BoolVar(&startKUDO, "start-kudo", false, "Start KUDO during the test run.")
testCmd.Flags().BoolVar(&skipDelete, "skip-delete", false, "If set, do not delete resources created during tests (helpful for debugging test failures, implies --skip-cluster-delete).")
testCmd.Flags().BoolVar(&skipClusterDelete, "skip-cluster-delete", false, "If set, do not delete the mocked control plane or kind cluster.")
// The default value here is only used for the help message. The default is actually enforced in RunTests.
testCmd.Flags().IntVar(&parallel, "parallel", 8, "The maximum number of tests to run at once.")

return testCmd
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/test/utils/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
// RunTests runs a Go test method without requiring the Go compiler.
// This does not currently support test caching.
// If testToRun is set to a non-empty string, it is passed as a `-run` argument to the go test harness.
func RunTests(testName string, testToRun string, testFunc func(*testing.T)) {
// If paralellism is set, it limits the number of concurrently running tests.
func RunTests(testName string, testToRun string, parallelism int, testFunc func(*testing.T)) {
// Set the verbose test flag to true since we are not using the regular go test CLI.
flag.Set("test.v", "true")

Expand All @@ -23,6 +24,12 @@ func RunTests(testName string, testToRun string, testFunc func(*testing.T)) {
flag.Set("test.run", fmt.Sprintf("//%s", testToRun))
}

parallelismStr := "8"
if parallelism != 0 {
parallelismStr = fmt.Sprintf("%d", parallelism)
}
flag.Set("test.parallel", parallelismStr)

os.Exit(testing.MainStart(&testDeps{}, []testing.InternalTest{
{
Name: testName,
Expand Down

0 comments on commit 0bb97d3

Please sign in to comment.