From 71da3fdcb232d5431712cf797942312e95073edd Mon Sep 17 00:00:00 2001 From: Matthew Jaffee Date: Mon, 24 Jan 2022 20:28:29 -0600 Subject: [PATCH] add docker-compose project to clustertests in CI to allow concurreny --- .gitlab/.gitlab-ci.yml | 1 - Dockerfile-clustertests | 4 +++ Makefile | 2 +- internal/clustertests/cluster_test.go | 37 ++++++++++++++++-------- internal/clustertests/docker-compose.yml | 1 + internal/clustertests/pause_node_test.go | 4 +-- 6 files changed, 33 insertions(+), 16 deletions(-) diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml index 38a576bd2..00d61373c 100644 --- a/.gitlab/.gitlab-ci.yml +++ b/.gitlab/.gitlab-ci.yml @@ -264,7 +264,6 @@ clustertests: stage: integration tags: - shell - - gcp rules: - if: '$CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "schedule" || $CI_PIPELINE_SOURCE == "web"' script: diff --git a/Dockerfile-clustertests b/Dockerfile-clustertests index 4a3a0c196..bcf80ac95 100644 --- a/Dockerfile-clustertests +++ b/Dockerfile-clustertests @@ -18,6 +18,10 @@ RUN chmod +x /pumba RUN apt update RUN apt install -y docker.io +# add docker-compose so tests can use it for stuff +ADD https://github.com/docker/compose/releases/latest/download/docker-compose-Linux-x86_64 /usr/local/bin/docker-compose +RUN chmod +x /usr/local/bin/docker-compose + RUN cp /go/bin/featurebase /featurebase COPY NOTICE /NOTICE diff --git a/Makefile b/Makefile index b89ed5f8f..00fc81c8e 100644 --- a/Makefile +++ b/Makefile @@ -155,7 +155,7 @@ clustertests: vendor $(DOCKER_COMPOSE) -f internal/clustertests/docker-compose.yml down $(DOCKER_COMPOSE) -f internal/clustertests/docker-compose.yml build $(DOCKER_COMPOSE) -f internal/clustertests/docker-compose.yml up -d pilosa1 pilosa2 pilosa3 - $(DOCKER_COMPOSE) -f internal/clustertests/docker-compose.yml run client1 + PROJECT=$(PROJECT) $(DOCKER_COMPOSE) -f internal/clustertests/docker-compose.yml run client1 $(DOCKER_COMPOSE) -f internal/clustertests/docker-compose.yml down diff --git a/internal/clustertests/cluster_test.go b/internal/clustertests/cluster_test.go index c6f4b0c3b..4bcdb2c58 100644 --- a/internal/clustertests/cluster_test.go +++ b/internal/clustertests/cluster_test.go @@ -16,6 +16,20 @@ import ( picli "github.com/molecula/featurebase/v3/http" ) +// container turns a docker-compose service name into a container name +// assuming the project name is set in the enviroment as PROJECT. This +// refers to the "-p" argument to docker-compose. NOTE: this assumes +// docker-compose joins the project name with a separating +// underscore... this may not always be true as I've seen a dash used +// as well, but I think it is true in recent versions. +func container(svc string) string { + project := "clustertests" + if p := os.Getenv("PROJECT"); p != "" { + project = p + } + return project + "_" + svc + "_1" +} + func TestClusterStuff(t *testing.T) { if os.Getenv("ENABLE_PILOSA_CLUSTER_TESTS") != "1" { t.Skip("pilosa cluster tests are not enabled") @@ -70,8 +84,7 @@ func TestClusterStuff(t *testing.T) { } } t.Run("long pause", func(t *testing.T) { - - pcmd := exec.Command("/pumba", "pause", "clustertests_pilosa3_1", "--duration", "10s") + pcmd := exec.Command("/pumba", "pause", container("pilosa3"), "--duration", "10s") pcmd.Stdout = os.Stdout pcmd.Stderr = os.Stderr t.Log("pausing pilosa3 for 10s") @@ -101,7 +114,7 @@ func TestClusterStuff(t *testing.T) { t.Run("backup", func(t *testing.T) { // do backup with node 1 down, but restart it after a few seconds - if err := sendCmd("docker", "stop", "clustertests_pilosa1_1"); err != nil { + if err := sendCmd("docker", "stop", container("pilosa1")); err != nil { t.Fatalf("sending stop command: %v", err) } var backupCmd *exec.Cmd @@ -111,7 +124,7 @@ func TestClusterStuff(t *testing.T) { t.Fatalf("sending backup command: %v", err) } time.Sleep(time.Second * 5) - if err = sendCmd("docker", "start", "clustertests_pilosa1_1"); err != nil { + if err = sendCmd("docker", "start", container("pilosa1")); err != nil { t.Fatalf("sending start command: %v", err) } @@ -137,12 +150,12 @@ func TestClusterStuff(t *testing.T) { t.Fatalf("starting restore: %v", err) } time.Sleep(time.Millisecond * 50) - if err = sendCmd("docker", "stop", "clustertests_pilosa2_1"); err != nil { + if err = sendCmd("docker", "stop", container("pilosa2")); err != nil { t.Fatalf("sending stop command: %v", err) } time.Sleep(time.Second * 10) - if err = sendCmd("docker", "start", "clustertests_pilosa2_1"); err != nil { + if err = sendCmd("docker", "start", container("pilosa2")); err != nil { t.Fatalf("sending stop command: %v", err) } if err := restoreCmd.Wait(); err != nil { @@ -157,25 +170,25 @@ func TestClusterStuff(t *testing.T) { t.Fatalf("sending second backup command: %v", err) } time.Sleep(time.Millisecond * 10) // want the backup to get started, then fail - if err = sendCmd("docker", "stop", "clustertests_pilosa1_1"); err != nil { + if err = sendCmd("docker", "stop", container("pilosa1")); err != nil { t.Fatalf("sending stop command: %v", err) } - if err = sendCmd("docker", "stop", "clustertests_pilosa2_1"); err != nil { + if err = sendCmd("docker", "stop", container("pilosa2")); err != nil { t.Fatalf("sending stop command: %v", err) } - if err = sendCmd("docker", "stop", "clustertests_pilosa3_1"); err != nil { + if err = sendCmd("docker", "stop", container("pilosa3")); err != nil { t.Fatalf("sending stop command: %v", err) } time.Sleep(time.Second * 5) - if err = sendCmd("docker", "start", "clustertests_pilosa1_1"); err != nil { + if err = sendCmd("docker", "start", container("pilosa1")); err != nil { t.Fatalf("sending start command: %v", err) } - if err = sendCmd("docker", "start", "clustertests_pilosa2_1"); err != nil { + if err = sendCmd("docker", "start", container("pilosa2")); err != nil { t.Fatalf("sending start command: %v", err) } - if err = sendCmd("docker", "start", "clustertests_pilosa3_1"); err != nil { + if err = sendCmd("docker", "start", container("pilosa3")); err != nil { t.Fatalf("sending start command: %v", err) } if err = backupCmd.Wait(); err == nil { diff --git a/internal/clustertests/docker-compose.yml b/internal/clustertests/docker-compose.yml index 2508de782..4154850dc 100644 --- a/internal/clustertests/docker-compose.yml +++ b/internal/clustertests/docker-compose.yml @@ -64,6 +64,7 @@ services: environment: - ENABLE_PILOSA_CLUSTER_TESTS=1 - GO111MODULE=on + - PROJECT=${PROJECT} networks: - pilosanet volumes: diff --git a/internal/clustertests/pause_node_test.go b/internal/clustertests/pause_node_test.go index d6c3863a8..20613ff61 100644 --- a/internal/clustertests/pause_node_test.go +++ b/internal/clustertests/pause_node_test.go @@ -44,12 +44,12 @@ func sendCmd(cmd string, args ...string) error { } func unpauseNode(node string) error { - unpauseArgs := []string{"container", "unpause", "clustertests_" + node + "_1"} + unpauseArgs := []string{"container", "unpause", container(node)} return sendCmd("docker", unpauseArgs...) } func pauseNode(node string) error { - pauseArgs := []string{"container", "pause", "clustertests_" + node + "_1"} + pauseArgs := []string{"container", "pause", container(node)} return sendCmd("docker", pauseArgs...) }