Skip to content

Commit deeef56

Browse files
committed
Prefer timeouts in order of -> spec, suite, default
1 parent e0aa8d8 commit deeef56

File tree

3 files changed

+27
-48
lines changed

3 files changed

+27
-48
lines changed

pkg/test/ginkgo/cmd_runsuite.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/onsi/ginkgo/v2"
2121
"github.com/openshift-eng/openshift-tests-extension/pkg/extension"
2222
configv1 "github.com/openshift/api/config/v1"
23+
"github.com/pkg/errors"
2324
"github.com/sirupsen/logrus"
2425
"github.com/spf13/pflag"
2526
"golang.org/x/mod/semver"
@@ -244,7 +245,10 @@ func (o *GinkgoRunSuiteOptions) Run(suite *TestSuite, clusterConfig *clusterdisc
244245
return err
245246
}
246247

247-
tests := externalBinaryTestsToOriginTestCases(specs)
248+
tests, err := extensionTestSpecsToOriginTestCases(specs)
249+
if err != nil {
250+
return errors.WithMessage(err, "could not convert test specs to origin test cases")
251+
}
248252

249253
// this ensures the tests are always run in random order to avoid
250254
// any intra-tests dependencies

pkg/test/ginkgo/test_runner.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,12 @@ func (c *commandContext) RunTestInNewProcess(ctx context.Context, test *testCase
313313
return ret
314314
}
315315

316-
results := test.binary.RunTests(ctx, c.timeout, testEnv, test.name)
316+
timeout := c.timeout
317+
if test.testTimeout > 0 {
318+
timeout = test.testTimeout
319+
}
320+
321+
results := test.binary.RunTests(ctx, timeout, testEnv, test.name)
317322
if len(results) != 1 {
318323
fmt.Fprintf(os.Stderr, "warning: expected 1 result from external binary; received %d", len(results))
319324
}

pkg/test/ginkgo/test_suite.go

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,65 +5,37 @@ import (
55
"time"
66

77
"github.com/onsi/ginkgo/v2/types"
8-
"github.com/openshift-eng/openshift-tests-extension/pkg/extension/extensiontests"
9-
"k8s.io/apimachinery/pkg/util/errors"
8+
"github.com/pkg/errors"
9+
"github.com/sirupsen/logrus"
1010

1111
"github.com/openshift/origin/pkg/test/extensions"
1212
)
1313

14-
func internalTestSpecsToOriginTestCases(suite *TestSuite, specs extensiontests.ExtensionTestSpecs) ([]*testCase, error) {
15-
var tests []*testCase
16-
var errs []error
17-
18-
specs.Walk(func(spec *extensiontests.ExtensionTestSpec) {
19-
tc := &testCase{
20-
name: spec.Name,
21-
rawName: spec.Name,
22-
}
23-
if suite != nil && suite.TestTimeout > 0 {
24-
tc.testTimeout = suite.TestTimeout
25-
}
26-
27-
tests = append(tests, tc)
28-
})
29-
if len(errs) > 0 {
30-
return nil, errors.NewAggregate(errs)
31-
}
32-
33-
return tests, nil
34-
}
35-
3614
var re = regexp.MustCompile(`.*\[Timeout:(.[^\]]*)\]`)
3715

38-
func externalBinaryTestsToOriginTestCases(specs extensions.ExtensionTestSpecs) []*testCase {
16+
func extensionTestSpecsToOriginTestCases(specs extensions.ExtensionTestSpecs) ([]*testCase, error) {
3917
var tests []*testCase
4018
for _, spec := range specs {
41-
tests = append(tests, &testCase{
19+
tc := &testCase{
4220
name: spec.Name,
4321
rawName: spec.Name,
4422
binary: spec.Binary,
45-
})
46-
}
47-
return tests
48-
}
49-
50-
func newTestCaseFromGinkgoSpec(spec types.TestSpec) (*testCase, error) {
51-
name := spec.Text()
52-
tc := &testCase{
53-
name: name,
54-
locations: spec.CodeLocations(),
55-
spec: spec,
56-
}
23+
}
5724

58-
if match := re.FindStringSubmatch(name); match != nil {
59-
testTimeOut, err := time.ParseDuration(match[1])
60-
if err != nil {
61-
return nil, err
25+
// Override timeout from suite with `[Timeout:X]` duration
26+
if match := re.FindStringSubmatch(tc.name); match != nil {
27+
testTimeOut, err := time.ParseDuration(match[1])
28+
if err != nil {
29+
return nil, errors.WithMessage(err, "failed to parse test timeout")
30+
}
31+
logrus.WithField("test", tc.name).Debugf("Overriding test timeout to %s", testTimeOut)
32+
tc.testTimeout = testTimeOut
6233
}
63-
tc.testTimeout = testTimeOut
34+
35+
tests = append(tests, tc)
6436
}
6537

66-
return tc, nil
38+
return tests, nil
6739
}
6840

6941
type testCase struct {
@@ -161,8 +133,6 @@ type TestSuite struct {
161133
Extension *extensions.Extension `json:"-"`
162134
}
163135

164-
165-
166136
type TestMatchFunc func(name string) bool
167137

168138
func (s *TestSuite) Filter(tests []*testCase) []*testCase {

0 commit comments

Comments
 (0)