Skip to content

Commit 972546a

Browse files
authored
Ensure integration test setup has a timeout. (#4478)
The top level context for integration tests comes from mage, which doesn't set a default timeout unless you give it one on the command line, which we don't do. Detect when the timeout wasn't set, and force a reasonable default.
1 parent c9bb164 commit 972546a

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

magefile.go

+24-9
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,22 @@ const (
7979
cloudImageTmpl = "docker.elastic.co/observability-ci/elastic-agent:%s"
8080
)
8181

82-
// Aliases for commands required by master makefile
83-
var Aliases = map[string]interface{}{
84-
"build": Build.All,
85-
"demo": Demo.Enroll,
86-
}
87-
var errNoManifest = errors.New("missing ManifestURL environment variable")
88-
var errNoAgentDropPath = errors.New("missing AGENT_DROP_PATH environment variable")
89-
var errAtLeastOnePlatform = errors.New("elastic-agent package is expected to build at least one platform package")
82+
var (
83+
// Aliases for commands required by master makefile
84+
Aliases = map[string]interface{}{
85+
"build": Build.All,
86+
"demo": Demo.Enroll,
87+
}
88+
89+
errNoManifest = errors.New("missing ManifestURL environment variable")
90+
errNoAgentDropPath = errors.New("missing AGENT_DROP_PATH environment variable")
91+
errAtLeastOnePlatform = errors.New("elastic-agent package is expected to build at least one platform package")
92+
93+
// goIntegTestTimeout is the timeout passed to each instance of 'go test' used in integration tests.
94+
goIntegTestTimeout = 2 * time.Hour
95+
// goProvisionAndTestTimeout is the timeout used for both provisioning and running tests.
96+
goProvisionAndTestTimeout = goIntegTestTimeout + 30*time.Minute
97+
)
9098

9199
func init() {
92100
common.RegisterCheckDeps(Update, Check.All)
@@ -2069,7 +2077,7 @@ func (Integration) TestOnRemote(ctx context.Context) error {
20692077
extraFlags = append(extraFlags, goTestFlags...)
20702078
}
20712079
extraFlags = append(extraFlags, "-test.shuffle", "on",
2072-
"-test.timeout", "2h", "-test.run", "^("+strings.Join(packageTests, "|")+")$")
2080+
"-test.timeout", goIntegTestTimeout.String(), "-test.run", "^("+strings.Join(packageTests, "|")+")$")
20732081
params := mage.GoTestArgs{
20742082
LogName: testName,
20752083
OutputFile: fileName + ".out",
@@ -2091,6 +2099,13 @@ func (Integration) TestOnRemote(ctx context.Context) error {
20912099
}
20922100

20932101
func integRunner(ctx context.Context, matrix bool, singleTest string) error {
2102+
if _, ok := ctx.Deadline(); !ok {
2103+
// If the context doesn't have a timeout (usually via the mage -t option), give it one.
2104+
var cancel context.CancelFunc
2105+
ctx, cancel = context.WithTimeout(ctx, goProvisionAndTestTimeout)
2106+
defer cancel()
2107+
}
2108+
20942109
for {
20952110
failedCount, err := integRunnerOnce(ctx, matrix, singleTest)
20962111
if err != nil {

0 commit comments

Comments
 (0)