Skip to content

Commit

Permalink
Fix nightly tests (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
deviantintegral authored Jul 7, 2023
2 parents 38b502d + a02c310 commit 4745333
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 40 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ env:
NIGHTLY_DDEV_PR_URL: "https://nightly.link/ddev/ddev/actions/runs/1720215802/ddev-linux-amd64.zip"
# Allow ddev get to use a github token to prevent rate limiting by tests
DDEV_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Allow `--HEAD` flag when running tests against HEAD
HOMEBREW_NO_INSTALL_FROM_API: 1

jobs:
tests:
Expand All @@ -47,6 +45,7 @@ jobs:
uses: Homebrew/actions/setup-homebrew@master
- name: Environment setup
run: |
brew update && brew upgrade
brew install mkcert
mkcert -install
git submodule init
Expand Down Expand Up @@ -82,7 +81,7 @@ jobs:
if: github.event.inputs.debug_enabled == 'true'

- name: tests
run: ./tests/bats/bin/bats tests
run: ./tests/bats/bin/bats -t tests

# keepalive-workflow adds a dummy commit if there's no other action here, keeps
# GitHub from turning off tests after 60 days
Expand Down
46 changes: 9 additions & 37 deletions tests/test.bats
Original file line number Diff line number Diff line change
@@ -1,61 +1,35 @@
setup_file() {
# Clean up any stale locks from previous test runs.
export GLOBAL_DDEV_LOCK=~/tmp/test-addon-ddev-playwright.lock
release_global_ddev
}

setup() {
set -eu -o pipefail
load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'
export DIR
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.."

echo "# user is ${USER}" >&3

# This was written so we could use bats' --jobs parameter to support multiple
# parallel tests. Unfortunately, running in parallel causes ddev state to
# become corrupt. I think these are ddev bugs. Since I figured out the temp
# handling already, I've added locks around the commands that potentially have
# global affects.

# We need to override /tmp because that is not mounted by default in macOS
# Docker software like Colima and Docker Desktop.
# https://stackoverflow.com/questions/31396985/why-is-mktemp-on-os-x-broken-with-a-command-that-worked-on-linux
mkdir -p ~/tmp
export DDEV_NON_INTERACTIVE=true

# Clean up any stale locks from previous test runs.
export GLOBAL_DDEV_LOCK=~/tmp/test-addon-ddev-playwright.lock
release_global_ddev
echo "# user is ${USER}" >&3

export TESTDIR
TESTDIR=$(mktemp -d "${HOME}/tmp/test-addon-ddev-playwright.XXXXXXXXX")
#TESTDIR=$(mktemp -d "${HOME}/tmp/test-addon-ddev-playwright.XXXXXXXXX")
export TESTDIR=~/tmp/test-addon-template
mkdir -p ${TESTDIR}
echo "# testdir is ${TESTDIR}" >&3

export PROJNAME=test-addon-ddev-playwright-${BATS_SUITE_TEST_NUMBER}
export DDEV_NON_INTERACTIVE=true

wait_for_global_ddev
ddev delete -Oy "${PROJNAME}" >/dev/null 2>&1 || true
cd "${TESTDIR}"
mkdir -p web
echo "# configuring project..." >&3
ddev config --project-name="${PROJNAME}" --docroot=web --project-type=php

# Traefik is required for basic auth to pass through to KasmVNC correctly.
ddev config global --use-traefik
# Allow to fail on ddev HEAD.
ddev config global --use-traefik || true

echo "# ddev start" >&3
ddev start -y >/dev/null
release_global_ddev
}

wait_for_global_ddev() {
while ! (set -o noclobber ; echo > "$GLOBAL_DDEV_LOCK"); do
sleep 1
done
}

release_global_ddev() {
rm -f "$GLOBAL_DDEV_LOCK"
}

health_checks() {
Expand All @@ -66,9 +40,7 @@ health_checks() {
teardown() {
set -eu -o pipefail
cd "${TESTDIR}" || ( printf "unable to cd to %s\n" "${TESTDIR}" && exit 1 )
wait_for_global_ddev
ddev delete -Oy "${PROJNAME}" >/dev/null 2>&1
release_global_ddev
[ "${TESTDIR}" != "" ] && rm -rf "${TESTDIR}"
}

Expand Down

0 comments on commit 4745333

Please sign in to comment.