File size: 4,547 Bytes
ff80158 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | #!/bin/bash
# Submit the Mosaic end-to-end browser test to SLURM.
#
# The job runs on an A100 node (tllihpcgpu[1-4]), activates the project
# virtualenv, starts a headless Chromium session via Playwright, and runs
# the full analysis pipeline against a live Gradio server.
#
# Usage:
# sbatch scripts/submit_e2e_test.sh
# sbatch --export=ALL,BROWSER=firefox scripts/submit_e2e_test.sh
# sbatch --export=ALL,HEADED=1 scripts/submit_e2e_test.sh # Xvfb window
#
# Environment variables (all optional):
# BROWSER - Playwright browser to use (chromium | firefox | webkit).
# Default: chromium
# HEADED - Set to 1 to run with a virtual display (Xvfb) instead of
# headless. Requires xvfb-run to be on PATH.
# HF_TOKEN - HuggingFace token for model download (if not already cached).
# PYTEST_EXTRA_ARGS - Extra arguments forwarded to pytest.
#SBATCH --job-name=mosaic-e2e
#SBATCH --partition=hpc
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=8
#SBATCH --gres=gpu:a100:1
#SBATCH --mem=64G
#SBATCH --time=01:30:00
#SBATCH --output=logs/e2e_%j.out
#SBATCH --error=logs/e2e_%j.err
set -euo pipefail
# ---------------------------------------------------------------------------
# Paths
# ---------------------------------------------------------------------------
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
VENV_PYTHON="$REPO_DIR/.venv/bin/python"
PYTEST="$REPO_DIR/.venv/bin/pytest"
LOG_DIR="$REPO_DIR/logs"
mkdir -p "$LOG_DIR"
echo "========================================"
echo "Mosaic E2E Browser Test"
echo "Job ID : ${SLURM_JOB_ID:-local}"
echo "Node : $(hostname)"
echo "Repo : $REPO_DIR"
echo "Started : $(date -Iseconds)"
echo "========================================"
# ---------------------------------------------------------------------------
# Activate virtualenv
# ---------------------------------------------------------------------------
source "$REPO_DIR/.venv/bin/activate"
# ---------------------------------------------------------------------------
# Verify prerequisites
# ---------------------------------------------------------------------------
if [ ! -f "$REPO_DIR/tests/testdata/948176.svs" ]; then
echo "ERROR: Test slide not found at tests/testdata/948176.svs" >&2
exit 1
fi
if ! "$VENV_PYTHON" -c "from playwright.sync_api import sync_playwright" 2>/dev/null; then
echo "ERROR: playwright not installed in venv. Run: pip install playwright && playwright install chromium" >&2
exit 1
fi
# Ensure Playwright browsers are installed (no-op if already present).
"$VENV_PYTHON" -m playwright install "${BROWSER:-chromium}" --with-deps 2>&1 | tail -5
# ---------------------------------------------------------------------------
# GPU sanity check
# ---------------------------------------------------------------------------
nvidia-smi --query-gpu=name,memory.total --format=csv,noheader | head -1
"$VENV_PYTHON" -c "import torch; print('CUDA available:', torch.cuda.is_available()); print('Device:', torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'CPU')"
# ---------------------------------------------------------------------------
# Build pytest command
# ---------------------------------------------------------------------------
PYTEST_CMD=(
"$PYTEST"
"tests/e2e/"
"--e2e"
"-v"
"--no-cov"
"--browser" "${BROWSER:-chromium}"
"--timeout=1200" # 20-min hard timeout per test
)
# Run headed via Xvfb virtual display if HEADED=1.
if [ "${HEADED:-0}" = "1" ]; then
if command -v xvfb-run &>/dev/null; then
PYTEST_CMD=("xvfb-run" "--auto-servernum" "--server-args=-screen 0 1920x1080x24" "${PYTEST_CMD[@]}" "--headed")
else
echo "WARNING: xvfb-run not found; falling back to headless mode." >&2
fi
fi
# Append any extra args passed via environment.
if [ -n "${PYTEST_EXTRA_ARGS:-}" ]; then
# Word-split is intentional here.
# shellcheck disable=SC2086
PYTEST_CMD+=($PYTEST_EXTRA_ARGS)
fi
# ---------------------------------------------------------------------------
# Run
# ---------------------------------------------------------------------------
cd "$REPO_DIR"
echo ""
echo "Command: ${PYTEST_CMD[*]}"
echo ""
"${PYTEST_CMD[@]}"
EXIT_CODE=$?
echo ""
echo "========================================"
if [ $EXIT_CODE -eq 0 ]; then
echo "RESULT: PASSED"
else
echo "RESULT: FAILED (exit $EXIT_CODE)"
fi
echo "Finished : $(date -Iseconds)"
echo "========================================"
exit $EXIT_CODE
|