Skip to content

Commit 6e3c7ae

Browse files
Mike Keeseymkeesey
authored andcommitted
Speed up kustainer creates and tear downs
Kustainer spawns Kusto through bash, so the normal shutdown signals do not get passed through. This means that the processes take 10s to shutdown after timeouts. Instead, create the container with an init process that can adopt the Kusto process with bash exits and can reap the process.
1 parent 24157cf commit 6e3c7ae

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pkg/testutils/kustainer/kustainer.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/Azure/adx-mon/pkg/testutils"
2020
"github.com/Azure/azure-kusto-go/kusto"
2121
"github.com/Azure/azure-kusto-go/kusto/kql"
22+
"github.com/docker/docker/api/types/container"
2223
"github.com/testcontainers/testcontainers-go"
2324
"github.com/testcontainers/testcontainers-go/modules/k3s"
2425
"github.com/testcontainers/testcontainers-go/wait"
@@ -39,15 +40,19 @@ type KustainerContainer struct {
3940
}
4041

4142
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*KustainerContainer, error) {
43+
initEnabled := true
4244
req := testcontainers.ContainerRequest{
4345
Image: img,
4446
ExposedPorts: []string{"8080/tcp"},
4547
Env: map[string]string{
4648
"ACCEPT_EULA": "Y",
4749
},
50+
HostConfigModifier: func(hc *container.HostConfig) {
51+
hc.Init = &initEnabled // Enable tini init process to handle reaping, which greatly speeds up shutting down this container
52+
},
4853
WaitingFor: wait.ForAll(
49-
wait.ForListeningPort("8080/tcp"),
50-
wait.ForLog(".*Hit 'CTRL-C' or 'CTRL-BREAK' to quit.*").AsRegexp(),
54+
wait.ForListeningPort("8080/tcp").WithPollInterval(50*time.Millisecond),
55+
wait.ForLog(".*Hit 'CTRL-C' or 'CTRL-BREAK' to quit.*").AsRegexp().WithPollInterval(50*time.Millisecond),
5156
),
5257
}
5358
genericContainerReq := testcontainers.GenericContainerRequest{

0 commit comments

Comments
 (0)