From d0dd673fb970d65cd63ec3af245e6402a79ef881 Mon Sep 17 00:00:00 2001 From: William Johansson Date: Fri, 4 Oct 2024 09:01:27 +0200 Subject: [PATCH] fix(cloud-spanner): stop emulator container with background context Use a background context with a 10s timeout when stopping the emulator. This makes sure the container is (at least attempted) stopped when e.g. pressing ctrl-c while running tests. --- tools/sgcloudspanner/emulator.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/sgcloudspanner/emulator.go b/tools/sgcloudspanner/emulator.go index 9ef868e9..a47a8c2e 100644 --- a/tools/sgcloudspanner/emulator.go +++ b/tools/sgcloudspanner/emulator.go @@ -44,6 +44,8 @@ func RunEmulator(ctx context.Context) (_ func(), err error) { } containerID := strings.TrimSpace(dockerRunStdout.String()) cleanup := func() { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() sg.Logger(ctx).Println("stopping down Cloud Spanner emulator...") cmd := sgdocker.Command(ctx, "kill", containerID) cmd.Stdout, cmd.Stderr = nil, nil