Improve e2e tests

Change the use of pkill with 'docker rm' as this will work more reliably (at least on MacOS). Trap the EXIT signal so we can perform a clean-up even if a test fails, so we don't pollute the system with a bunch of stopped containers. Increase the timeout from two to three seconds in order for the tests to work reliably on MacOS (the two second waiting period was consistenly to short for all tests to work). Update the Makefile so when we run the container in order to compile the package we make sure the (stopped) container is removed.
This commit is contained in:
jorianvo 2017-09-21 22:02:13 +02:00
parent 267a78bfd4
commit 517179fa2f
2 changed files with 49 additions and 31 deletions

View File

@ -93,6 +93,7 @@ bin/$(ARCH)/$(BIN): build-dirs
-v $$(pwd)/bin/$(ARCH):/go/bin/linux_$(ARCH) \ -v $$(pwd)/bin/$(ARCH):/go/bin/linux_$(ARCH) \
-v $$(pwd)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)_static \ -v $$(pwd)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)_static \
-w /go/src/$(PKG) \ -w /go/src/$(PKG) \
--rm \
$(BUILD_IMAGE) \ $(BUILD_IMAGE) \
/bin/sh -c " \ /bin/sh -c " \
ARCH=$(ARCH) \ ARCH=$(ARCH) \

View File

@ -13,9 +13,8 @@ function testcase() {
function fail() { function fail() {
echo "FAIL: " "$@" echo "FAIL: " "$@"
sleep 2 sleep 3
pkill git-sync || true remove_sync_container || true
ps auxw | grep git-sync
exit 1 exit 1
} }
@ -47,6 +46,16 @@ function assert_file_eq() {
fail "file $1 does not contain '$2': $(cat $1)" fail "file $1 does not contain '$2': $(cat $1)"
} }
function finish() {
if [ $? -ne 0 ]; then
echo "The directory $DIR was not removed as it contains"\
"log files useful for debugging"
remove_sync_container
fi
}
trap finish INT EXIT
######################### #########################
# main # main
######################### #########################
@ -65,16 +74,24 @@ if [[ -z "$DIR" ]]; then
fi fi
echo "test root is $DIR" echo "test root is $DIR"
CONTAINER_NAME=git-sync-$RANDOM
function GIT_SYNC() { function GIT_SYNC() {
#./bin/amd64/git-sync "$@" #./bin/amd64/git-sync "$@"
docker run \ docker run \
--name $CONTAINER_NAME \
-i \ -i \
-u $(id -u):$(id -g) \ -u $(id -u):$(id -g) \
-v "$DIR":"$DIR" \ -v "$DIR":"$DIR" \
--rm \
e2e/git-sync-amd64:$(make -s version) \ e2e/git-sync-amd64:$(make -s version) \
"$@" "$@"
} }
function remove_sync_container() {
# Verify the container is running using 'docker top' before removing
docker top $CONTAINER_NAME >/dev/null 2>&1 && docker rm -f $CONTAINER_NAME
}
REPO="$DIR/repo" REPO="$DIR/repo"
mkdir "$REPO" mkdir "$REPO"
@ -124,25 +141,25 @@ GIT_SYNC \
--repo="$REPO" \ --repo="$REPO" \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & --dest="link" > "$DIR"/log."$TESTCASE" 2>&1 &
sleep 2 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$TESTCASE 1" assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
# Move forward # Move forward
echo "$TESTCASE 2" > "$REPO"/file echo "$TESTCASE 2" > "$REPO"/file
git -C "$REPO" commit -qam "$TESTCASE 2" git -C "$REPO" commit -qam "$TESTCASE 2"
sleep 2 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$TESTCASE 2" assert_file_eq "$ROOT"/link/file "$TESTCASE 2"
# Move backward # Move backward
git -C "$REPO" reset -q --hard HEAD^ git -C "$REPO" reset -q --hard HEAD^
sleep 2 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$TESTCASE 1" assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
# Wrap up # Wrap up
pkill git-sync remove_sync_container
wait wait
pass pass
@ -160,25 +177,25 @@ GIT_SYNC \
--rev=HEAD \ --rev=HEAD \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & --dest="link" > "$DIR"/log."$TESTCASE" 2>&1 &
sleep 2 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$TESTCASE 1" assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
# Move HEAD forward # Move HEAD forward
echo "$TESTCASE 2" > "$REPO"/file echo "$TESTCASE 2" > "$REPO"/file
git -C "$REPO" commit -qam "$TESTCASE 2" git -C "$REPO" commit -qam "$TESTCASE 2"
sleep 2 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$TESTCASE 2" assert_file_eq "$ROOT"/link/file "$TESTCASE 2"
# Move HEAD backward # Move HEAD backward
git -C "$REPO" reset -q --hard HEAD^ git -C "$REPO" reset -q --hard HEAD^
sleep 2 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$TESTCASE 1" assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
# Wrap up # Wrap up
pkill git-sync remove_sync_container
wait wait
pass pass
@ -198,7 +215,7 @@ GIT_SYNC \
--branch="$BRANCH" \ --branch="$BRANCH" \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & --dest="link" > "$DIR"/log."$TESTCASE" 2>&1 &
sleep 2 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$TESTCASE 1" assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
@ -207,7 +224,7 @@ git -C "$REPO" checkout -q "$BRANCH"
echo "$TESTCASE 2" > "$REPO"/file echo "$TESTCASE 2" > "$REPO"/file
git -C "$REPO" commit -qam "$TESTCASE 2" git -C "$REPO" commit -qam "$TESTCASE 2"
git -C "$REPO" checkout -q master git -C "$REPO" checkout -q master
sleep 2 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$TESTCASE 2" assert_file_eq "$ROOT"/link/file "$TESTCASE 2"
@ -215,12 +232,12 @@ assert_file_eq "$ROOT"/link/file "$TESTCASE 2"
git -C "$REPO" checkout -q "$BRANCH" git -C "$REPO" checkout -q "$BRANCH"
git -C "$REPO" reset -q --hard HEAD^ git -C "$REPO" reset -q --hard HEAD^
git -C "$REPO" checkout -q master git -C "$REPO" checkout -q master
sleep 2 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$TESTCASE 1" assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
# Wrap up # Wrap up
pkill git-sync remove_sync_container
wait wait
pass pass
@ -239,7 +256,7 @@ GIT_SYNC \
--rev="$TAG" \ --rev="$TAG" \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & --dest="link" > "$DIR"/log."$TESTCASE" 2>&1 &
sleep 2 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$TESTCASE 1" assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
@ -247,26 +264,26 @@ assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
echo "$TESTCASE 2" > "$REPO"/file echo "$TESTCASE 2" > "$REPO"/file
git -C "$REPO" commit -qam "$TESTCASE 2" git -C "$REPO" commit -qam "$TESTCASE 2"
git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 2" >/dev/null git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 2" >/dev/null
sleep 2 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$TESTCASE 2" assert_file_eq "$ROOT"/link/file "$TESTCASE 2"
# Move the tag backward # Move the tag backward
git -C "$REPO" reset -q --hard HEAD^ git -C "$REPO" reset -q --hard HEAD^
git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 3" >/dev/null git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 3" >/dev/null
sleep 2 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$TESTCASE 1" assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
# Add something after the tag # Add something after the tag
echo "$TESTCASE 3" > "$REPO"/file echo "$TESTCASE 3" > "$REPO"/file
git -C "$REPO" commit -qam "$TESTCASE 3" git -C "$REPO" commit -qam "$TESTCASE 3"
sleep 2 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$TESTCASE 1" assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
# Wrap up # Wrap up
pkill git-sync remove_sync_container
wait wait
pass pass
@ -288,7 +305,7 @@ GIT_SYNC \
--rev="$TAG" \ --rev="$TAG" \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & --dest="link" > "$DIR"/log."$TESTCASE" 2>&1 &
sleep 2 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$TESTCASE 1" assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
@ -298,7 +315,7 @@ echo "$TESTCASE 2" > "$REPO"/file
git -C "$REPO" commit -qam "$TESTCASE 2" git -C "$REPO" commit -qam "$TESTCASE 2"
git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 1" >/dev/null git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 1" >/dev/null
git -C "$REPO" checkout -q master git -C "$REPO" checkout -q master
sleep 2 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$TESTCASE 2" assert_file_eq "$ROOT"/link/file "$TESTCASE 2"
@ -307,7 +324,7 @@ git -C "$REPO" checkout -q "$BRANCH"
git -C "$REPO" reset -q --hard HEAD^ git -C "$REPO" reset -q --hard HEAD^
git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 1" >/dev/null git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 1" >/dev/null
git -C "$REPO" checkout -q master git -C "$REPO" checkout -q master
sleep 2 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$TESTCASE 1" assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
@ -316,7 +333,7 @@ git -C "$REPO" checkout -q "$BRANCH"
echo "$TESTCASE 3" > "$REPO"/file echo "$TESTCASE 3" > "$REPO"/file
git -C "$REPO" commit -qam "$TESTCASE 3" git -C "$REPO" commit -qam "$TESTCASE 3"
git -C "$REPO" checkout -q master git -C "$REPO" checkout -q master
sleep 2 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$TESTCASE 1" assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
@ -324,12 +341,12 @@ assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
git -C "$REPO" checkout -q "$BRANCH" git -C "$REPO" checkout -q "$BRANCH"
git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 3" >/dev/null git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 3" >/dev/null
git -C "$REPO" checkout -q master git -C "$REPO" checkout -q master
sleep 2 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$TESTCASE 3" assert_file_eq "$ROOT"/link/file "$TESTCASE 3"
# Wrap up # Wrap up
pkill git-sync remove_sync_container
wait wait
pass pass
@ -347,25 +364,25 @@ GIT_SYNC \
--rev="$REV" \ --rev="$REV" \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & --dest="link" > "$DIR"/log."$TESTCASE" 2>&1 &
sleep 2 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$TESTCASE 1" assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
# Commit something new # Commit something new
echo "$TESTCASE 2" > "$REPO"/file echo "$TESTCASE 2" > "$REPO"/file
git -C "$REPO" commit -qam "$TESTCASE 2" git -C "$REPO" commit -qam "$TESTCASE 2"
sleep 2 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$TESTCASE 1" assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
# Revert the last change # Revert the last change
git -C "$REPO" reset -q --hard HEAD^ git -C "$REPO" reset -q --hard HEAD^
sleep 2 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$TESTCASE 1" assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
# Wrap up # Wrap up
pkill git-sync remove_sync_container
wait wait
pass pass
@ -384,7 +401,7 @@ GIT_SYNC \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" \ --dest="link" \
--one-time > "$DIR"/log."$TESTCASE" 2>&1 --one-time > "$DIR"/log."$TESTCASE" 2>&1
sleep 2 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
assert_file_eq "$ROOT"/link/file "$TESTCASE" assert_file_eq "$ROOT"/link/file "$TESTCASE"