Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub action to run integration tests #1

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Test

on: [pull_request]

jobs:
run-tests:
name: Run Tests
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: pyproject.toml

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e .[tests]

- name: Run tests
run: ./scripts/test.sh

61 changes: 61 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash

# Runs user/integration tests.

set -e

PROJECT_ROOT="$(git rev-parse --show-toplevel)"
TMP_DIRS_FILE=/tmp/p9fs-dirs
PY9S_SERVER_PID=/tmp/p9fs.pid
PY9S_SERVER_LOG=/tmp/p9fs.log

function mymktempdir {
local tmpdir="$(mktemp -d)"
echo "$tmpdir" | tee -a $TMP_DIRS_FILE
}

function run_py9s_server {
local exported_dir="$1"
cd "$PROJECT_ROOT/src"
python -m py9p -p 1234 -w -d -r "$exported_dir" &> $PY9S_SERVER_LOG &
echo $! > $PY9S_SERVER_PID

echo Waiting for 9p server ...
SERVER_READY=""
for i in $(seq 1 5); do
if nc -d -w 1 -z 127.0.0.1 1234; then
SERVER_READY="true"
break
fi
sleep 1
done
if [[ ! $SERVER_READY ]]; then
echo 9p server failed to start
exit 1
fi
}

function user_tests {
local exported_dir="$1"
cd "$PROJECT_ROOT/src"
python -m pytest -v -rA ../tests/user --exported "$exported_dir"
}

function cleanup {
if [[ -f $PY9S_SERVER_PID ]]; then
kill "$(<$PY9S_SERVER_PID)" || true
rm -f "$PY9S_SERVER_PID"
fi
if [[ -f $TMP_DIRS_FILE ]]; then
xargs -n1 -r rm -rf < $TMP_DIRS_FILE
rm -f $TMP_DIRS_FILE
fi
}

trap cleanup EXIT

rm -f "$TMP_DIRS_FILE"

EXPORTED_DIR=""$(mymktempdir)""
run_py9s_server "$EXPORTED_DIR"
user_tests "$EXPORTED_DIR"