Merge pull request #203 from thockin/e2e-various

e2e: various fixes and cleanups
This commit is contained in:
Kubernetes Prow Robot 2019-11-20 02:15:20 -08:00 committed by GitHub
commit 4905dc62a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 93 additions and 51 deletions

View File

@ -61,7 +61,7 @@ make container REGISTRY=e2e VERSION=$(make -s version)
DIR="" DIR=""
for i in $(seq 1 10); do for i in $(seq 1 10); do
DIR="/tmp/git-sync-test.$RANDOM" DIR="/tmp/git-sync-test.$RANDOM$RANDOM"
mkdir "$DIR" && break mkdir "$DIR" && break
done done
if [[ -z "$DIR" ]]; then if [[ -z "$DIR" ]]; then
@ -80,7 +80,7 @@ function finish() {
trap finish INT EXIT trap finish INT EXIT
CONTAINER_NAME=git-sync-$RANDOM CONTAINER_NAME=git-sync-$RANDOM$RANDOM
function GIT_SYNC() { function GIT_SYNC() {
#./bin/linux_amd64/git-sync "$@" #./bin/linux_amd64/git-sync "$@"
docker run \ docker run \
@ -119,7 +119,9 @@ touch "$REPO"/file
git -C "$REPO" add file git -C "$REPO" add file
git -C "$REPO" commit -aqm "init file" git -C "$REPO" commit -aqm "init file"
##############################################
# Test HEAD one-time # Test HEAD one-time
##############################################
testcase "head-once" testcase "head-once"
# First sync # First sync
echo "$TESTCASE" > "$REPO"/file echo "$TESTCASE" > "$REPO"/file
@ -127,20 +129,22 @@ git -C "$REPO" commit -qam "$TESTCASE"
GIT_SYNC \ GIT_SYNC \
--logtostderr \ --logtostderr \
--v=5 \ --v=5 \
--wait=0.1 \ --one-time \
--repo="$REPO" \ --repo="file://$REPO" \
--branch=master \ --branch=master \
--rev=HEAD \ --rev=HEAD \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" \ --dest="link" \
--one-time > "$DIR"/log."$TESTCASE" 2>&1 > "$DIR"/log."$TESTCASE" 2>&1
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"
# Wrap up # Wrap up
pass pass
##############################################
# Test default syncing # Test default syncing
##############################################
testcase "default-sync" testcase "default-sync"
# First sync # First sync
echo "$TESTCASE 1" > "$REPO"/file echo "$TESTCASE 1" > "$REPO"/file
@ -149,9 +153,10 @@ GIT_SYNC \
--logtostderr \ --logtostderr \
--v=5 \ --v=5 \
--wait=0.1 \ --wait=0.1 \
--repo="$REPO" \ --repo="file://$REPO" \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & --dest="link" \
> "$DIR"/log."$TESTCASE" 2>&1 &
sleep 3 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
@ -174,7 +179,9 @@ remove_sync_container
wait wait
pass pass
##############################################
# Test HEAD syncing # Test HEAD syncing
##############################################
testcase "head-sync" testcase "head-sync"
# First sync # First sync
echo "$TESTCASE 1" > "$REPO"/file echo "$TESTCASE 1" > "$REPO"/file
@ -183,11 +190,12 @@ GIT_SYNC \
--logtostderr \ --logtostderr \
--v=5 \ --v=5 \
--wait=0.1 \ --wait=0.1 \
--repo="$REPO" \ --repo="file://$REPO" \
--branch=master \ --branch=master \
--rev=HEAD \ --rev=HEAD \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & --dest="link" \
> "$DIR"/log."$TESTCASE" 2>&1 &
sleep 3 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
@ -210,7 +218,9 @@ remove_sync_container
wait wait
pass pass
##############################################
# Test branch syncing # Test branch syncing
##############################################
testcase "branch-sync" testcase "branch-sync"
BRANCH="$TESTCASE"--BRANCH BRANCH="$TESTCASE"--BRANCH
# First sync # First sync
@ -222,10 +232,11 @@ GIT_SYNC \
--logtostderr \ --logtostderr \
--v=5 \ --v=5 \
--wait=0.1 \ --wait=0.1 \
--repo="$REPO" \ --repo="file://$REPO" \
--branch="$BRANCH" \ --branch="$BRANCH" \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & --dest="link" \
> "$DIR"/log."$TESTCASE" 2>&1 &
sleep 3 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
@ -252,7 +263,9 @@ remove_sync_container
wait wait
pass pass
##############################################
# Test tag syncing # Test tag syncing
##############################################
testcase "tag-sync" testcase "tag-sync"
TAG="$TESTCASE"--TAG TAG="$TESTCASE"--TAG
# First sync # First sync
@ -263,10 +276,11 @@ GIT_SYNC \
--logtostderr \ --logtostderr \
--v=5 \ --v=5 \
--wait=0.1 \ --wait=0.1 \
--repo="$REPO" \ --repo="file://$REPO" \
--rev="$TAG" \ --rev="$TAG" \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & --dest="link" \
> "$DIR"/log."$TESTCASE" 2>&1 &
sleep 3 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
@ -298,7 +312,9 @@ remove_sync_container
wait wait
pass pass
##############################################
# Test tag syncing with annotated tags # Test tag syncing with annotated tags
##############################################
testcase "tag-sync-annotated" testcase "tag-sync-annotated"
TAG="$TESTCASE"--TAG TAG="$TESTCASE"--TAG
# First sync # First sync
@ -309,10 +325,11 @@ GIT_SYNC \
--logtostderr \ --logtostderr \
--v=5 \ --v=5 \
--wait=0.1 \ --wait=0.1 \
--repo="$REPO" \ --repo="file://$REPO" \
--rev="$TAG" \ --rev="$TAG" \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & --dest="link" \
> "$DIR"/log."$TESTCASE" 2>&1 &
sleep 3 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
@ -344,7 +361,9 @@ remove_sync_container
wait wait
pass pass
##############################################
# Test cross-branch tag syncing # Test cross-branch tag syncing
##############################################
testcase "cross-branch-tag-sync" testcase "cross-branch-tag-sync"
BRANCH="$TESTCASE"--BRANCH BRANCH="$TESTCASE"--BRANCH
TAG="$TESTCASE"--TAG TAG="$TESTCASE"--TAG
@ -358,10 +377,11 @@ GIT_SYNC \
--logtostderr \ --logtostderr \
--v=5 \ --v=5 \
--wait=0.1 \ --wait=0.1 \
--repo="$REPO" \ --repo="file://$REPO" \
--rev="$TAG" \ --rev="$TAG" \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & --dest="link" \
> "$DIR"/log."$TESTCASE" 2>&1 &
sleep 3 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
@ -407,7 +427,9 @@ remove_sync_container
wait wait
pass pass
##############################################
# Test rev syncing # Test rev syncing
##############################################
testcase "rev-sync" testcase "rev-sync"
# First sync # First sync
echo "$TESTCASE 1" > "$REPO"/file echo "$TESTCASE 1" > "$REPO"/file
@ -417,10 +439,11 @@ GIT_SYNC \
--logtostderr \ --logtostderr \
--v=5 \ --v=5 \
--wait=0.1 \ --wait=0.1 \
--repo="$REPO" \ --repo="file://$REPO" \
--rev="$REV" \ --rev="$REV" \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & --dest="link" \
> "$DIR"/log."$TESTCASE" 2>&1 &
sleep 3 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
@ -443,7 +466,9 @@ remove_sync_container
wait wait
pass pass
##############################################
# Test rev-sync one-time # Test rev-sync one-time
##############################################
testcase "rev-once" testcase "rev-once"
# First sync # First sync
echo "$TESTCASE" > "$REPO"/file echo "$TESTCASE" > "$REPO"/file
@ -452,20 +477,21 @@ REV=$(git -C "$REPO" rev-list -n1 HEAD)
GIT_SYNC \ GIT_SYNC \
--logtostderr \ --logtostderr \
--v=5 \ --v=5 \
--wait=0.1 \ --one-time \
--repo="$REPO" \ --repo="file://$REPO" \
--rev="$REV" \ --rev="$REV" \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" \ --dest="link" \
--one-time > "$DIR"/log."$TESTCASE" 2>&1 > "$DIR"/log."$TESTCASE" 2>&1
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"
# Wrap up # Wrap up
pass pass
##############################################
# Test syncing after a crash # Test syncing after a crash
##############################################
testcase "crash-cleanup-retry" testcase "crash-cleanup-retry"
# First sync # First sync
echo "$TESTCASE 1" > "$REPO"/file echo "$TESTCASE 1" > "$REPO"/file
@ -474,10 +500,10 @@ GIT_SYNC \
--logtostderr \ --logtostderr \
--v=5 \ --v=5 \
--one-time \ --one-time \
--repo="$REPO" \ --repo="file://$REPO" \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & --dest="link" \
sleep 3 > "$DIR"/log."$TESTCASE" 2>&1
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"
@ -488,43 +514,46 @@ GIT_SYNC \
--logtostderr \ --logtostderr \
--v=5 \ --v=5 \
--one-time \ --one-time \
--repo="$REPO" \ --repo="file://$REPO" \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & --dest="link" \
sleep 3 > "$DIR"/log."$TESTCASE" 2>&1
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
pass pass
##############################################
# Test sync loop timeout # Test sync loop timeout
##############################################
testcase "sync-loop-timeout" testcase "sync-loop-timeout"
# First sync # First sync
echo "$TESTCASE 1" > "$REPO"/file echo "$TESTCASE 1" > "$REPO"/file
git -C "$REPO" commit -qam "$TESTCASE 1" git -C "$REPO" commit -qam "$TESTCASE 1"
GIT_SYNC \ GIT_SYNC \
--git=$SLOW_GIT \ --git=$SLOW_GIT \
--timeout=1 \
--logtostderr \ --logtostderr \
--v=5 \ --v=5 \
--one-time \ --one-time \
--repo="$REPO" \ --timeout=1 \
--repo="file://$REPO" \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & --dest="link" \
sleep 3 > "$DIR"/log."$TESTCASE" 2>&1 || true
# check for failure # check for failure
assert_file_absent "$ROOT"/link/file assert_file_absent "$ROOT"/link/file
# run with slow_git but without timing out # run with slow_git but without timing out
GIT_SYNC \ GIT_SYNC \
--git=$SLOW_GIT \ --git=$SLOW_GIT \
--timeout=16 \
--logtostderr \ --logtostderr \
--v=5 \ --v=5 \
--wait=0.1 \ --wait=0.1 \
--repo="$REPO" \ --timeout=16 \
--repo="file://$REPO" \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & --dest="link" \
> "$DIR"/log."$TESTCASE" 2>&1 &
sleep 10 sleep 10
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
@ -541,7 +570,9 @@ remove_sync_container
wait wait
pass pass
##############################################
# Test depth syncing # Test depth syncing
##############################################
testcase "depth" testcase "depth"
# First sync # First sync
echo "$TESTCASE 1" > "$REPO"/file echo "$TESTCASE 1" > "$REPO"/file
@ -551,10 +582,11 @@ GIT_SYNC \
--logtostderr \ --logtostderr \
--v=5 \ --v=5 \
--wait=0.1 \ --wait=0.1 \
--repo="$REPO" \ --repo="file://$REPO" \
--depth="$expected_depth" \ --depth="$expected_depth" \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & --dest="link" \
> "$DIR"/log."$TESTCASE" 2>&1 &
sleep 3 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
@ -589,7 +621,9 @@ remove_sync_container
wait wait
pass pass
##############################################
# Test webhook # Test webhook
##############################################
testcase "webhook" testcase "webhook"
NCPORT=8888 NCPORT=8888
# First sync # First sync
@ -598,16 +632,17 @@ git -C "$REPO" commit -qam "$TESTCASE 1"
GIT_SYNC \ GIT_SYNC \
--logtostderr \ --logtostderr \
--v=5 \ --v=5 \
--repo="$REPO" \ --repo="file://$REPO" \
--root="$ROOT" \ --root="$ROOT" \
--webhook-url="http://127.0.0.1:$NCPORT" \ --webhook-url="http://127.0.0.1:$NCPORT" \
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & --dest="link" \
> "$DIR"/log."$TESTCASE" 2>&1 &
# check that basic call works # check that basic call works
{ (echo -e "HTTP/1.1 200 OK\r\n" | nc -q1 -l $NCPORT > /dev/null) &} { (echo -e "HTTP/1.1 200 OK\r\n" | nc -q1 -l $NCPORT > /dev/null) &}
NCPID=$! NCPID=$!
sleep 3 sleep 3
if kill -0 $NCPID > /dev/null 2>&1; then if kill -0 $NCPID > /dev/null 2>&1; then
fail "webhook not called, server still running" fail "webhook 1 not called, server still running"
fi fi
# Move forward # Move forward
echo "$TESTCASE 2" > "$REPO"/file echo "$TESTCASE 2" > "$REPO"/file
@ -617,21 +652,23 @@ git -C "$REPO" commit -qam "$TESTCASE 2"
NCPID=$! NCPID=$!
sleep 3 sleep 3
if kill -0 $NCPID > /dev/null 2>&1; then if kill -0 $NCPID > /dev/null 2>&1; then
fail "2 webhook not called, server still running" fail "webhook 2 not called, server still running"
fi fi
# Now return 200, ensure that it gets called # Now return 200, ensure that it gets called
{ (echo -e "HTTP/1.1 200 OK\r\n" | nc -q1 -l $NCPORT > /dev/null) &} { (echo -e "HTTP/1.1 200 OK\r\n" | nc -q1 -l $NCPORT > /dev/null) &}
NCPID=$! NCPID=$!
sleep 3 sleep 3
if kill -0 $NCPID > /dev/null 2>&1; then if kill -0 $NCPID > /dev/null 2>&1; then
fail "3 webhook not called, server still running" fail "webhook 3 not called, server still running"
fi fi
# Wrap up # Wrap up
remove_sync_container remove_sync_container
wait wait
pass pass
##############################################
# Test http handler # Test http handler
##############################################
testcase "http" testcase "http"
BINDPORT=8888 BINDPORT=8888
# First sync # First sync
@ -640,12 +677,13 @@ git -C "$REPO" commit -qam "$TESTCASE 1"
GIT_SYNC \ GIT_SYNC \
--logtostderr \ --logtostderr \
--v=5 \ --v=5 \
--repo="$REPO" \ --repo="file://$REPO" \
--root="$ROOT" \ --root="$ROOT" \
--http-bind=":$BINDPORT" \ --http-bind=":$BINDPORT" \
--http-metrics \ --http-metrics \
--http-pprof \ --http-pprof \
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & --dest="link" \
> "$DIR"/log."$TESTCASE" 2>&1 &
sleep 2 sleep 2
# check that health endpoint is alive # check that health endpoint is alive
if [[ $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:$BINDPORT) -ne 200 ]] ; then if [[ $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:$BINDPORT) -ne 200 ]] ; then
@ -664,7 +702,9 @@ remove_sync_container
wait wait
pass pass
##############################################
# Test submodule sync # Test submodule sync
##############################################
testcase "submodule-sync" testcase "submodule-sync"
# Init submodule repo # Init submodule repo
@ -694,11 +734,10 @@ GIT_SYNC \
--logtostderr \ --logtostderr \
--v=5 \ --v=5 \
--wait=0.1 \ --wait=0.1 \
--repo="$REPO" \ --repo="file://$REPO" \
--branch=master \
--rev=HEAD \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & --dest="link" \
> "$DIR"/log."$TESTCASE" 2>&1 &
sleep 3 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT"/link/file
@ -762,7 +801,9 @@ remove_sync_container
wait wait
pass pass
##############################################
# Test submodules depth syncing # Test submodules depth syncing
##############################################
testcase "submodule-sync-depth" testcase "submodule-sync-depth"
# Init submodule repo # Init submodule repo
@ -784,10 +825,11 @@ GIT_SYNC \
--logtostderr \ --logtostderr \
--v=5 \ --v=5 \
--wait=0.1 \ --wait=0.1 \
--repo="$REPO" \ --repo="file://$REPO" \
--depth="$expected_depth" \ --depth="$expected_depth" \
--root="$ROOT" \ --root="$ROOT" \
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & --dest="link" \
> "$DIR"/log."$TESTCASE" 2>&1 &
sleep 3 sleep 3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/$SUBMODULE_REPO_NAME/submodule assert_file_exists "$ROOT"/link/$SUBMODULE_REPO_NAME/submodule