Skip to content

Commit

Permalink
GitHub action to run integration tests (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
pbchekin authored Dec 19, 2023
1 parent 2324ca0 commit b6cbb5e
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
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"

0 comments on commit b6cbb5e

Please sign in to comment.