Skip to content

Commit c0f36d0

Browse files
committed
inttests: kill test runner containers faster
Previously, each test scenario would wait 10 seconds to remove the test container. This is because the test containers use 'sleep' as the entrypoint. Sleep doesn't have SIGTERM handling, so when it runs as PID 1, SIGTERM doesn't do anything and the container engine resorts to SIGKILL after 10 seconds. Kill test runner containers immediately (without the 10 second wait) if they use --entrypoint sleep. This greatly speeds up integration tests. Signed-off-by: Adam Cmiel <acmiel@redhat.com>
1 parent 1d3c39e commit c0f36d0

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

integration_tests/framework/runner_container.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"path"
77
"path/filepath"
88
"runtime"
9+
"strconv"
910
"strings"
1011

1112
cliWrappers "github.com/konflux-ci/konflux-build-cli/pkg/cliwrappers"
@@ -40,6 +41,10 @@ type TestRunnerContainer struct {
4041
executor cliWrappers.CliExecutorInterface
4142

4243
containerStatus ContainerStatus
44+
45+
// Time to wait before sending SIGKILL to an unresponsive container when deleting
46+
// (does not apply to docker), see the Delete() method
47+
killTimeout *int
4348
}
4449

4550
// ContainerOption is a functional-style option for configuring TestRunnerContainer.
@@ -108,6 +113,10 @@ func WithWorkdir(workdir string) ContainerOption {
108113
}
109114
}
110115

116+
func (c *TestRunnerContainer) SetKillTimeout(timeout int) {
117+
c.killTimeout = &timeout
118+
}
119+
111120
func (c *TestRunnerContainer) AddEnv(key, value string) {
112121
c.ensureContainerNotStarted()
113122
c.env[key] = value
@@ -226,6 +235,9 @@ func (c *TestRunnerContainer) Start() error {
226235

227236
if c.ReplaceEntrypoint {
228237
args = append(args, "--entrypoint", "sleep", c.image, "infinity")
238+
// 'sleep' is the entrypoint, it runs as PID 1 and will never respond to SIGTERM.
239+
// Send SIGKILL immediately.
240+
c.SetKillTimeout(0)
229241
} else {
230242
args = append(args, c.image)
231243
}
@@ -258,7 +270,12 @@ func (c *TestRunnerContainer) StartWithRegistryIntegration(imageRegistry ImageRe
258270
}
259271

260272
func (c *TestRunnerContainer) Delete() error {
261-
stdout, stderr, _, err := c.executor.Execute(containerTool, "rm", "-f", c.name)
273+
args := []string{"rm", "-f", c.name}
274+
// Docker always uses SIGKILL immediately and doesn't have a --time flag
275+
if c.killTimeout != nil && containerTool != "docker" {
276+
args = append(args, "--time", strconv.Itoa(*c.killTimeout))
277+
}
278+
stdout, stderr, _, err := c.executor.Execute(containerTool, args...)
262279
if err == nil {
263280
c.containerStatus = ContainerStatus_Deleted
264281
} else {

0 commit comments

Comments
 (0)