Skip to content

Commit

Permalink
Add testcase for sync failure (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
int128 authored Feb 6, 2021
1 parent b5bf2fb commit a184ab4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
28 changes: 22 additions & 6 deletions e2e_test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,35 @@ GITHUB_PR_NUMBER ?= 0

all:

test:
test: testcase1 testcase2

.NOTPARALLEL: testcase1 testcase2
testcase1:
# create a pull request
git checkout -b $(MAIN_BRANCH_NAME)-fixture1
sed -i -e 's/name: echoserver/name: echoserver-fixture1/g' helloworld/deployment/echoserver.yaml
git commit -a -m "fixture1"
git commit -a -m "e2e-test-fixture1"
git push origin $(MAIN_BRANCH_NAME)-fixture1
gh pr create --base $(MAIN_BRANCH_NAME) --title "e2e-test: fixture1" --body "This is created by #$(GITHUB_PR_NUMBER)"
gh pr create --base $(MAIN_BRANCH_NAME) --title "e2e-test: sync success" --body "This is created by e2e-test of #$(GITHUB_PR_NUMBER)"
gh pr merge --squash
# wait for sync
git checkout $(MAIN_BRANCH_NAME)
git pull origin --ff-only $(MAIN_BRANCH_NAME)
./wait-for-synced.sh helloworld
./wait-for-sync-status.sh helloworld Synced
kubectl -n helloworld rollout status deployment echoserver-fixture1
sleep 10

testcase2:
# create a pull request
git checkout -b $(MAIN_BRANCH_NAME)-fixture2
sed -i -e 's/app: echoserver/app: echoserver-fixture2/g' helloworld/deployment/echoserver.yaml
git commit -a -m "e2e-test-fixture2"
git push origin $(MAIN_BRANCH_NAME)-fixture2
gh pr create --base $(MAIN_BRANCH_NAME) --title "e2e-test: sync failure" --body "This is created by e2e-test of #$(GITHUB_PR_NUMBER)"
gh pr merge --squash
# wait for sync
git checkout $(MAIN_BRANCH_NAME)
git pull origin --ff-only $(MAIN_BRANCH_NAME)
./wait-for-sync-status.sh helloworld OutOfSync

# environment
cluster: $(KUBECONFIG)
Expand All @@ -41,7 +56,7 @@ deploy-argocd: cluster
git push origin $(MAIN_BRANCH_NAME)
kustomize build applications | sed -e "s/MAIN_BRANCH_NAME/$(MAIN_BRANCH_NAME)/g" | kubectl apply -f -
kubectl -n argocd rollout status statefulsets argocd-application-controller
./wait-for-synced.sh helloworld
./wait-for-sync-status.sh helloworld Synced

deploy-controller: cluster build-controller
kind load docker-image controller:latest --name $(CLUSTER_NAME)
Expand All @@ -63,4 +78,5 @@ ci-setup:
ci-cleanup:
-git push origin --delete $(MAIN_BRANCH_NAME)
-git push origin --delete $(MAIN_BRANCH_NAME)-fixture1
-git push origin --delete $(MAIN_BRANCH_NAME)-fixture2
-kubectl -n argocd-commenter-system logs -l control-plane=controller-manager --all-containers
11 changes: 6 additions & 5 deletions e2e_test/wait-for-synced.sh → e2e_test/wait-for-sync-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ set -eu

application_name="$1"
want_revision="$(git rev-parse HEAD)"
want_status="$2"

for (( i = 0; i < 15; i++ )); do
for (( i = 0; i < 10; i++ )); do
status="$(kubectl -n argocd get application "$application_name" '-ojsonpath={.status.sync.status}/{.status.sync.revision}')"
echo "[wait-for-synced] got: $status"
echo "[wait-for-synced] want: Synced/$want_revision"
if [[ $status == Synced/$want_revision ]]; then
echo "[wait-for-sync-status] got: $status"
echo "[wait-for-sync-status] want: $want_status/$want_revision"
if [[ $status == $want_status/$want_revision ]]; then
exit 0
fi
echo "[wait-for-synced] retry after ${i}s"
echo "[wait-for-sync-status] retry after ${i}s"
sleep "$i"
done
exit 1

0 comments on commit a184ab4

Please sign in to comment.