From 0d838d12480214b2aa321cce7d6982534475cbba Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Fri, 24 Apr 2015 13:52:14 -0700 Subject: [PATCH 1/3] split up unit-tests and use 4 containers (they're free) --- tests.mk | 4 ++++ tests/ci/parallel_runner.sh | 11 ++++++++--- tests/ci/unit_test_runner.sh | 37 ++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100755 tests/ci/unit_test_runner.sh diff --git a/tests.mk b/tests.mk index 5c1931e54..1c2cb01a9 100644 --- a/tests.mk +++ b/tests.mk @@ -61,7 +61,11 @@ lint: unit-tests: @echo running unit tests... +ifndef UNIT_TEST_BATCH @$(QUIET) bats tests/unit +else + @$(QUIET) ./tests/ci/unit_test_runner.sh $$UNIT_TEST_BATCH +endif deploy-test-clojure: @echo deploying config app... diff --git a/tests/ci/parallel_runner.sh b/tests/ci/parallel_runner.sh index 68e1038ff..612ec0809 100755 --- a/tests/ci/parallel_runner.sh +++ b/tests/ci/parallel_runner.sh @@ -2,16 +2,21 @@ case "$CIRCLE_NODE_INDEX" in 0) - echo "=====> make unit-tests" - sudo -E make -e unit-tests + echo "=====> make unit-tests (1/2)" + sudo -E UNIT_TEST_BATCH=1 make -e unit-tests ;; 1) + echo "=====> make unit-tests (2/2)" + sudo -E UNIT_TEST_BATCH=2 make -e unit-tests + ;; + + 2) echo "=====> make deploy-tests (buildstep release)" sudo -E make -e deploy-tests ;; - 2) + 3) echo "=====> make deploy-tests (buildstep master)" docker rmi -f progrium/buildstep && \ sudo -E BUILD_STACK=true make -e stack && \ diff --git a/tests/ci/unit_test_runner.sh b/tests/ci/unit_test_runner.sh new file mode 100755 index 000000000..ebf5df679 --- /dev/null +++ b/tests/ci/unit_test_runner.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +is_number() { + local NUMBER=$1; local NUM_RE='^[0-9]+$' + if [[ $NUMBER =~ $NUM_RE ]];then + return 0 + else + return 1 + fi +} + +usage() { + echo "usage: $0 1|2" + exit 0 +} + +BATCH_NUM="$1" +is_number $BATCH_NUM || usage + +TESTS=( $(find $(dirname $0)/../unit -maxdepth 1 -name "*.bats") ) +HALF_TESTS=$(( ${#TESTS[@]} / 2 )) +FIRST_HALF=${TESTS[@]:0:${HALF_TESTS}} +LAST_HALF=${TESTS[@]:${HALF_TESTS}:${#TESTS[@]}} + +case "$BATCH_NUM" in + 1) + bats $FIRST_HALF + ;; + + 2) + bats $LAST_HALF + ;; + + *) + usage + ;; +esac From a529f6fce8550e9e7ee86d8e05b297bf3b157d7d Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Fri, 24 Apr 2015 14:02:44 -0700 Subject: [PATCH 2/3] lintball --- tests/ci/unit_test_runner.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/ci/unit_test_runner.sh b/tests/ci/unit_test_runner.sh index ebf5df679..9f5e2ce39 100755 --- a/tests/ci/unit_test_runner.sh +++ b/tests/ci/unit_test_runner.sh @@ -17,18 +17,18 @@ usage() { BATCH_NUM="$1" is_number $BATCH_NUM || usage -TESTS=( $(find $(dirname $0)/../unit -maxdepth 1 -name "*.bats") ) +TESTS=($(find "$(dirname $0)"/../unit -maxdepth 1 -name "*.bats")) HALF_TESTS=$(( ${#TESTS[@]} / 2 )) -FIRST_HALF=${TESTS[@]:0:${HALF_TESTS}} -LAST_HALF=${TESTS[@]:${HALF_TESTS}:${#TESTS[@]}} +FIRST_HALF=("${TESTS[@]:0:${HALF_TESTS}}") +LAST_HALF=("${TESTS[@]:${HALF_TESTS}:${#TESTS[@]}}") case "$BATCH_NUM" in 1) - bats $FIRST_HALF + bats "${FIRST_HALF[@]}" ;; 2) - bats $LAST_HALF + bats "${LAST_HALF[@]}" ;; *) From 0c715d4b399457c1ad8b5d1f9d183abc8915ff95 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Fri, 24 Apr 2015 14:11:45 -0700 Subject: [PATCH 3/3] more test efficiencies and cleanup --- circle.yml | 14 ++------------ tests.mk | 1 - tests/ci/parallel_runner.sh | 33 ++++++++++++++++++++++++++------ tests/deploy/config.bats | 10 ---------- tests/deploy/gitsubmodules.bats | 10 ---------- tests/deploy/go.bats | 10 ---------- tests/deploy/java.bats | 10 ---------- tests/deploy/multi.bats | 10 ---------- tests/deploy/nodejs-express.bats | 10 ---------- tests/deploy/php.bats | 11 ----------- tests/deploy/python-flask.bats | 10 ---------- tests/deploy/static.bats | 11 ----------- 12 files changed, 29 insertions(+), 111 deletions(-) delete mode 100644 tests/deploy/config.bats delete mode 100644 tests/deploy/gitsubmodules.bats delete mode 100644 tests/deploy/go.bats delete mode 100644 tests/deploy/java.bats delete mode 100644 tests/deploy/multi.bats delete mode 100644 tests/deploy/nodejs-express.bats delete mode 100644 tests/deploy/php.bats delete mode 100644 tests/deploy/python-flask.bats delete mode 100644 tests/deploy/static.bats diff --git a/circle.yml b/circle.yml index 34ce1b34c..3ab50cccf 100644 --- a/circle.yml +++ b/circle.yml @@ -5,19 +5,9 @@ dependencies: cache_directories: - "~/docker" override: - # need to add the dokku user to the docker group - - sudo -E CI=true make -e sshcommand - - sudo usermod -G docker dokku - - sudo -E CI=true DOCKER_VERSION=1.5.0 make -e install: { timeout: 300 } - - make -e ci-dependencies - #### circle does some weird *expletive* with regards to root and gh auth (needed for gitsubmodules test) - - sudo rsync -a ~ubuntu/.ssh/ ~root/.ssh/ - - sudo chown -R root:root ~root/.ssh/ - - sudo sed -e 's:/home/ubuntu:/root:g' ~root/.ssh/config - #### - - sudo -E make -e setup-deploy-tests + - ./tests/ci/parallel_runner.sh setup: { timeout: 300 } post: - sudo -E make -e lint test: override: - - ./tests/ci/parallel_runner.sh: { parallel: true, timeout: 1800 } + - ./tests/ci/parallel_runner.sh testing: { parallel: true, timeout: 1800 } diff --git a/tests.mk b/tests.mk index 1c2cb01a9..c4d126bbb 100644 --- a/tests.mk +++ b/tests.mk @@ -129,7 +129,6 @@ deploy-test-static: deploy-tests: @echo running deploy tests... - # @$(QUIET) bats tests/deploy @$(QUIET) $(MAKE) deploy-test-config @$(QUIET) $(MAKE) deploy-test-clojure @$(QUIET) $(MAKE) deploy-test-dockerfile diff --git a/tests/ci/parallel_runner.sh b/tests/ci/parallel_runner.sh index 612ec0809..8a664b8b8 100755 --- a/tests/ci/parallel_runner.sh +++ b/tests/ci/parallel_runner.sh @@ -1,25 +1,46 @@ #!/usr/bin/env bash +MODE="$1"; MODE=${MODE:="testing"} + +setup_circle() { + MAKE_ENV="CI=true DOCKER_VERSION=1.5.0" + [[ "$1" == "buildstack" ]] && MAKE_ENV+=" BUILD_STACK=true " + echo "setting up with MAKE_ENV: $MAKE_ENV" + sudo -E CI=true make -e sshcommand + # need to add the dokku user to the docker group + sudo usermod -G docker dokku + #### circle does some weird *expletive* with regards to root and gh auth (needed for gitsubmodules test) + sudo rsync -a ~ubuntu/.ssh/ ~root/.ssh/ + sudo chown -R root:root ~root/.ssh/ + sudo sed --in-place 's:/home/ubuntu:/root:g' ~root/.ssh/config + #### + sudo -E $MAKE_ENV make -e install + sudo -E make -e setup-deploy-tests + make -e ci-dependencies +} + case "$CIRCLE_NODE_INDEX" in 0) - echo "=====> make unit-tests (1/2)" + echo "=====> make unit-tests (1/2) on CIRCLE_NODE_INDEX: $CIRCLE_NODE_INDEX" + [[ "$MODE" == "setup" ]] && setup_circle && exit 0 sudo -E UNIT_TEST_BATCH=1 make -e unit-tests ;; 1) - echo "=====> make unit-tests (2/2)" + echo "=====> make unit-tests (2/2) on CIRCLE_NODE_INDEX: $CIRCLE_NODE_INDEX" + [[ "$MODE" == "setup" ]] && setup_circle && exit 0 sudo -E UNIT_TEST_BATCH=2 make -e unit-tests ;; 2) - echo "=====> make deploy-tests (buildstep release)" + echo "=====> make deploy-tests (buildstep release) on CIRCLE_NODE_INDEX: $CIRCLE_NODE_INDEX" + [[ "$MODE" == "setup" ]] && setup_circle && exit 0 sudo -E make -e deploy-tests ;; 3) - echo "=====> make deploy-tests (buildstep master)" - docker rmi -f progrium/buildstep && \ - sudo -E BUILD_STACK=true make -e stack && \ + echo "=====> make deploy-tests (buildstep master) on CIRCLE_NODE_INDEX: $CIRCLE_NODE_INDEX" + [[ "$MODE" == "setup" ]] && setup_circle buildstack && exit 0 sudo -E make -e deploy-tests ;; esac diff --git a/tests/deploy/config.bats b/tests/deploy/config.bats deleted file mode 100644 index f8177e53e..000000000 --- a/tests/deploy/config.bats +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bats - -load ../unit/test_helper - -@test "deploy config app" { - run bash -c "cd tests && ./test_deploy ./apps/config dokku.me" - echo "output: "$output - echo "status: "$status - assert_success -} diff --git a/tests/deploy/gitsubmodules.bats b/tests/deploy/gitsubmodules.bats deleted file mode 100644 index b5b66fdcf..000000000 --- a/tests/deploy/gitsubmodules.bats +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bats - -load ../unit/test_helper - -@test "deploy gitsubmodules app" { - run bash -c "cd tests && ./test_deploy ./apps/gitsubmodules dokku.me" - echo "output: "$output - echo "status: "$status - assert_success -} diff --git a/tests/deploy/go.bats b/tests/deploy/go.bats deleted file mode 100644 index cdd75c2c2..000000000 --- a/tests/deploy/go.bats +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bats - -load ../unit/test_helper - -@test "deploy go app" { - run bash -c "cd tests && ./test_deploy ./apps/go dokku.me" - echo "output: "$output - echo "status: "$status - assert_success -} diff --git a/tests/deploy/java.bats b/tests/deploy/java.bats deleted file mode 100644 index 560ad28e3..000000000 --- a/tests/deploy/java.bats +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bats - -load ../unit/test_helper - -@test "deploy java app" { - run bash -c "cd tests && ./test_deploy ./apps/java dokku.me" - echo "output: "$output - echo "status: "$status - assert_success -} diff --git a/tests/deploy/multi.bats b/tests/deploy/multi.bats deleted file mode 100644 index e938e21fc..000000000 --- a/tests/deploy/multi.bats +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bats - -load ../unit/test_helper - -@test "deploy multi app" { - run bash -c "cd tests && ./test_deploy ./apps/multi dokku.me" - echo "output: "$output - echo "status: "$status - assert_success -} diff --git a/tests/deploy/nodejs-express.bats b/tests/deploy/nodejs-express.bats deleted file mode 100644 index 2fcc82dc8..000000000 --- a/tests/deploy/nodejs-express.bats +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bats - -load ../unit/test_helper - -@test "deploy nodejs-express app" { - run bash -c "cd tests && ./test_deploy ./apps/nodejs-express dokku.me" - echo "output: "$output - echo "status: "$status - assert_success -} diff --git a/tests/deploy/php.bats b/tests/deploy/php.bats deleted file mode 100644 index 06bfa081b..000000000 --- a/tests/deploy/php.bats +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bats - -load ../unit/test_helper - -@test "deploy php app" { - skip "fails. ref: https://github.com/progrium/buildstep/issues/126" - run bash -c "cd tests && ./test_deploy ./apps/php dokku.me" - echo "output: "$output - echo "status: "$status - assert_success -} diff --git a/tests/deploy/python-flask.bats b/tests/deploy/python-flask.bats deleted file mode 100644 index 1834e8fc8..000000000 --- a/tests/deploy/python-flask.bats +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bats - -load ../unit/test_helper - -@test "deploy python-flask app" { - run bash -c "cd tests && ./test_deploy ./apps/python-flask dokku.me" - echo "output: "$output - echo "status: "$status - assert_success -} diff --git a/tests/deploy/static.bats b/tests/deploy/static.bats deleted file mode 100644 index bef621f29..000000000 --- a/tests/deploy/static.bats +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bats - -load ../unit/test_helper - -@test "deploy static app" { - skip "fails on apt-get update..." - run bash -c "cd tests && ./test_deploy ./apps/static dokku.me" - echo "output: "$output - echo "status: "$status - assert_success -}