diff --git a/pkg/acceptance/cluster/dockercluster.go b/pkg/acceptance/cluster/dockercluster.go index 34c0352503a8..0fef62f91997 100644 --- a/pkg/acceptance/cluster/dockercluster.go +++ b/pkg/acceptance/cluster/dockercluster.go @@ -887,6 +887,7 @@ func (l *DockerCluster) Cleanup(ctx context.Context, preserveLogs bool) { } for _, v := range volumes { if preserveLogs && v.Name() == "logs" { + log.Infof(ctx, "preserving log directory: %s", l.volumesDir) continue } if err := os.RemoveAll(filepath.Join(l.volumesDir, v.Name())); err != nil { diff --git a/pkg/acceptance/util_docker.go b/pkg/acceptance/util_docker.go index a0f332840502..8104e2f59a14 100644 --- a/pkg/acceptance/util_docker.go +++ b/pkg/acceptance/util_docker.go @@ -22,6 +22,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/base" "github.com/cockroachdb/cockroach/pkg/build/bazel" "github.com/cockroachdb/cockroach/pkg/security/username" + "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/containerd/containerd/platforms" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" @@ -121,18 +122,33 @@ func testDocker( cfg.Nodes = append(cfg.Nodes, cluster.NodeConfig{Stores: []cluster.StoreConfig{{}}}) } l := StartCluster(ctx, t, cfg).(*cluster.DockerCluster) - defer l.AssertAndStop(ctx, t) + + var preserveLogs bool + defer func() { + // Check the final health of the cluster nodes and + // stop the cluster after that. + l.AssertAndStop(ctx, t) + + // Note: we must be careful to clean up the volumes *after* + // the cluster has been shut down (in the `AssertAndStop` call). + // Otherwise, the directory removal will cause the cluster nodes + // to crash and report abnormal termination, even when the test + // succeeds otherwise. + log.Infof(ctx, "cleaning up docker volume") + l.Cleanup(ctx, preserveLogs) + }() if len(l.Nodes) > 0 { containerConfig.Env = append(containerConfig.Env, "PGHOST="+l.Hostname(0)) } + log.Infof(ctx, "starting one-shot container") err = l.OneShot( ctx, acceptanceImage, types.ImagePullOptions{}, containerConfig, hostConfig, platforms.DefaultSpec(), "docker-"+name, ) - preserveLogs := err != nil - l.Cleanup(ctx, preserveLogs) + log.Infof(ctx, "one-shot container terminated: %v", err) + preserveLogs = err != nil }) return err }