Skip to content

Commit

Permalink
Fix default test timeout and make default test timeout configurable a…
Browse files Browse the repository at this point in the history
…t the test suite level. (#534)

* Fix default test timeout and make default test timeout configurable at the test suite level.

The KEP defined the default assertion timeout as 300 seconds, but we actually implemented it as 10 seconds. I think 300 seconds is much too high for the default, so I've adjusted it to 30 in both the implementation and KEP.

This also makes the timeout configurable at the test suite level so that it can be configured for an entire test suite instead of just a specific assert.

* appease linter
  • Loading branch information
jbarrick-mesosphere authored Jul 9, 2019
1 parent 324b7e7 commit 31b453e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
4 changes: 3 additions & 1 deletion keps/0008-operator-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ type TestSuite struct {
StartControlPlane bool
// Whether or not to start the KUDO controller for the tests.
StartKUDO bool
// Override the default assertion timeout of 30 seconds (in seconds).
Timeout int
}
```
Expand Down Expand Up @@ -295,7 +297,7 @@ When searching the assertion file for a test step, if a `TestAssert` object is f
type TestAssert struct {
// The type meta object, should always be a GVK of kudo.k8s.io/v1alpha1/TestAssert.
TypeMeta
// Override the default timeout of 300 seconds (in seconds).
// Override the default timeout of 30 seconds (in seconds).
Timeout int
}
```
Expand Down
4 changes: 3 additions & 1 deletion pkg/apis/kudo/v1alpha1/test_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type TestSuite struct {
StartKUDO bool `json:"startKUDO"`
// If set, do not delete the resources after running the tests.
SkipDelete bool `json:"skipDelete"`
// Override the default timeout of 30 seconds (in seconds).
Timeout int `json:"timeout"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down Expand Up @@ -54,7 +56,7 @@ type TestStep struct {
type TestAssert struct {
// The type meta object, should always be a GVK of kudo.k8s.io/v1alpha1/TestAssert.
metav1.TypeMeta `json:",inline"`
// Override the default timeout of 300 seconds (in seconds).
// Override the default timeout of 30 seconds (in seconds).
Timeout int `json:"timeout"`
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/test/case.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Case struct {
Name string
Dir string
SkipDelete bool
Timeout int

Client client.Client
DiscoveryClient discovery.DiscoveryInterface
Expand Down Expand Up @@ -152,6 +153,7 @@ func (t *Case) LoadTestSteps() error {

for index, files := range testStepFiles {
testStep := &Step{
Timeout: t.Timeout,
Index: int(index),
Asserts: []runtime.Object{},
Apply: []runtime.Object{},
Expand Down
10 changes: 10 additions & 0 deletions pkg/test/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (h *Harness) LoadTests(dir string) ([]*Case, error) {
}

tests = append(tests, &Case{
Timeout: h.GetTimeout(),
Steps: []*Step{},
Name: file.Name(),
Dir: filepath.Join(dir, file.Name()),
Expand All @@ -62,6 +63,15 @@ func (h *Harness) LoadTests(dir string) ([]*Case, error) {
return tests, nil
}

// GetTimeout returns the configured timeout for the test suite.
func (h *Harness) GetTimeout() int {
timeout := 30
if h.TestSuite.Timeout != 0 {
timeout = 30
}
return timeout
}

// RunTestEnv starts a Kubernetes API server and etcd server for use in the
// tests and returns the Kubernetes configuration.
func (h *Harness) RunTestEnv() (*rest.Config, error) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/test/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Step struct {
Apply []runtime.Object
Errors []runtime.Object

Timeout int
DiscoveryClient discovery.DiscoveryInterface
Client client.Client
Logger testutils.Logger
Expand Down Expand Up @@ -159,7 +160,7 @@ func (s *Step) Create(namespace string) []error {

// GetTimeout gets the timeout defined for the test step.
func (s *Step) GetTimeout() int {
timeout := 10
timeout := s.Timeout
if s.Assert != nil && s.Assert.Timeout != 0 {
timeout = s.Assert.Timeout
}
Expand Down

0 comments on commit 31b453e

Please sign in to comment.