diff --git a/test/connect_dcs.sh b/test/connect_dcs.sh index 6de242e..b9a2bd1 100755 --- a/test/connect_dcs.sh +++ b/test/connect_dcs.sh @@ -2,7 +2,7 @@ sleep 5 -cat > /tmp/connect.erl <<- EOF +cat > /tmp/connect.erl <<- EOF #!/usr/bin/env escript %%! -smp enable -sname erlshell -setcookie antidote main(_Args) -> diff --git a/test/docker-antidote-3dcs.yml b/test/docker-antidote-3dcs.yml index 0a586c3..a7f1b17 100644 --- a/test/docker-antidote-3dcs.yml +++ b/test/docker-antidote-3dcs.yml @@ -2,6 +2,7 @@ version: "2.1" services: antidote1: image: antidotedb/antidote:latest + container_name: antidote1 ports: - "8087:8087" environment: @@ -10,14 +11,16 @@ services: antidote2: image: antidotedb/antidote:latest + container_name: antidote2 ports: - "8088:8087" environment: NODE_NAME: "antidote@antidote2" SHORT_NAME: "true" - + antidote3: image: antidotedb/antidote:latest + container_name: antidote3 ports: - "8089:8087" environment: @@ -25,7 +28,8 @@ services: SHORT_NAME: "true" link: - image: erlang:19 + image: erlang:21-slim + container_name: antidote_link healthcheck: test: ["CMD", "test", "-f", "/tmp/ready"] interval: 3s diff --git a/test/fs_distributed_test.sh b/test/fs_distributed_test.sh index 62ce0fa..1e8727f 100755 --- a/test/fs_distributed_test.sh +++ b/test/fs_distributed_test.sh @@ -5,16 +5,24 @@ echo "Start distributed file system test" -docker-compose -f ./test/docker-antidote-3dcs.yml down >/dev/null 2>&1 +docker-compose -rmi all -f ./test/docker-antidote-3dcs.yml down >/dev/null 2>&1 docker-compose -f ./test/docker-antidote-3dcs.yml up -d #>/dev/null 2>&1 -sleep 25 + +wait_antidote antidote1 +wait_antidote antidote2 +wait_antidote antidote3 +while [ "healthy" != `docker inspect --format='{{ .State.Health.Status}}' antidote_link` ]; do + echo "Waiting for Antidote instances to form a cluster..." + sleep 2 +done +sleep 3 rm -rf d1 d2 d3 mkdir -p d1 d2 d3 node ./src/antidote-fs.js -m d1 -a "localhost:8087" > /dev/null & node ./src/antidote-fs.js -m d2 -a "localhost:8088" > /dev/null & node ./src/antidote-fs.js -m d3 -a "localhost:8089" > /dev/null & -sleep 3 +sleep 5 EXIT=0 @@ -24,8 +32,8 @@ echo hello there 2 > ./d2/test.txt sleep 2 echo -n "File conflict.................." if [[ -f ./d3/test.txt-CONFLICT_0 && -f ./d3/test.txt-CONFLICT_1 ]] -then ok; -else ko; EXIT=1; +then ok; +else ko; EXIT=1; fi # Directory naming conflict: merge directories @@ -44,7 +52,7 @@ if [[ -d ./d3/dirC && \ -f ./d3/dirC/mydirAfile.txt && $(< ./d3/dirC/dirBB/mydirBBfile.txt) == $(echo "hello world B") && $(< ./d1/dirC/mydirAfile.txt) == $(echo "hello world A") ]] -then ok; +then ok; else ko; EXIT=1; fi diff --git a/test/test.sh b/test/test.sh index ece8a11..7025f4b 100755 --- a/test/test.sh +++ b/test/test.sh @@ -1,10 +1,13 @@ #!/bin/bash -start_single_instance() { +. ./test/utils.sh + +start_single_instance() { + stop_remove_antidote_containers echo "Starting single instance" - docker rm -fv $(docker ps -q -f ancestor=antidotedb/antidote) 2> /dev/null - docker run -d --rm -it -p "8087:8087" antidotedb/antidote > /dev/null - sleep 20 + docker run -d --name antidote --rm -it -p "8087:8087" antidotedb/antidote:latest > /dev/null + wait_antidote antidote + rm -rf d1; mkdir d1 node ./src/antidote-fs.js -m d1 -a "localhost:8087" > /dev/null & sleep 5 @@ -14,7 +17,7 @@ start_single_instance() { stop_single_instance() { echo "Stopping single instance" fusermount -u ./d1 - docker rm -fv $(docker ps -a -q) > /dev/null 2>&1 + stop_remove_antidote_containers echo "Single instance stopped" } diff --git a/test/utils.sh b/test/utils.sh index d6579a6..6a9a65a 100644 --- a/test/utils.sh +++ b/test/utils.sh @@ -4,9 +4,23 @@ RED='\033[0;31m' GREEN='\033[0;32m' NC='\033[0m' # No Color -rnd_str() { +rnd_str() { echo $(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 5 | head -n 1) } ok() { echo -e "${GREEN}OK${NC}"; } ko() { echo -e "${RED}KO${NC}"; } + +wait_antidote() { + while ! docker exec -it $1 grep "Application antidote started" /opt/antidote/log/console.log; do + echo "Waiting 2 seconds for $1 to start up..." + sleep 2 + done +} + +stop_remove_antidote_containers() { + # WARNING: this command stops and removes all containers derived by + # antidotedb/antidote! + docker rm -fv $(docker ps -q -f ancestor=antidotedb/antidote) 2> /dev/null +} +