Skip to content
Open
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
148 changes: 148 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
name: Tests

on:
push:
branches:
- master
- release/**
pull_request:
branches:
- master
- release/**

concurrency:
group: tests-${{ github.ref }}
cancel-in-progress: true

jobs:
# ── Stage 1: Unit tests ──
unit-test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]

steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v2
with:
version: "latest"
enable-cache: true

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- name: Install dependencies
run: uv sync --all-extras --group test

- name: Run unit tests
run: |
mkdir -p .tmp/test_data/logs
uv run pytest tests/unit \
-m "not need_ray and not need_docker and not need_admin and not need_admin_and_network" \
--timeout=60 \
--tb=short \
-v

# ── Stage 2: Integration tests (Ray + Docker + Admin) ──
integration-test:
runs-on: ubuntu-latest
needs: unit-test
strategy:
matrix:
python-version: ["3.11"]

steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v2
with:
version: "latest"
enable-cache: true

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- name: Install dependencies
run: uv sync --all-extras --group test

- name: Pull Docker images
run: docker pull python:3.11

- name: Start Ray cluster
run: |
uv run ray start --head --disable-usage-stats --num-cpus=2 --memory=6442450944
sleep 3
uv run ray status

- name: Run fast tests (no Ray/Docker/Admin)
env:
ROCK_WORKER_ENV_TYPE: uv
ROCK_LOGGING_LEVEL: WARNING
run: |
mkdir -p .tmp/test_data/logs
uv run pytest tests/integration \
-m "not need_ray and not need_docker and not need_admin and not need_admin_and_network" \
--timeout=300 \
--log-cli-level=WARNING \
--tb=short \
-v

- name: Run Docker-dependent tests
if: success() || failure()
env:
ROCK_WORKER_ENV_TYPE: uv
ROCK_LOGGING_LEVEL: WARNING
run: |
uv run pytest tests/ \
-m "need_docker" \
--timeout=600 \
--log-cli-level=WARNING \
--tb=short \
-v

- name: Run Ray-dependent tests
if: success() || failure()
env:
ROCK_WORKER_ENV_TYPE: uv
ROCK_LOGGING_LEVEL: WARNING
run: |
uv run pytest tests/ \
-m "need_ray" \
--timeout=600 \
--log-cli-level=WARNING \
--tb=short \
-v

- name: Run Admin-dependent tests
if: success() || failure()
env:
ROCK_WORKER_ENV_TYPE: uv
ROCK_LOGGING_LEVEL: WARNING
run: |
uv run pytest tests/ \
-m "need_admin" \
--timeout=600 \
--log-cli-level=WARNING \
--tb=short \
-v

- name: Run Admin + Network tests
if: success() || failure()
env:
ROCK_WORKER_ENV_TYPE: uv
ROCK_LOGGING_LEVEL: WARNING
run: |
uv run pytest tests/ \
-m "need_admin_and_network" \
--timeout=600 \
--log-cli-level=WARNING \
--tb=short \
-v

- name: Stop Ray cluster
if: always()
run: uv run ray stop --force || true
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: help init install-hooks check-setup preflight-check
.PHONY: help init install-hooks check-setup preflight-check test-unit test-integration

# Default target
.DEFAULT_GOAL := help
Expand Down Expand Up @@ -80,3 +80,13 @@ preflight-check: ## Check prerequisites for running ROCK admin server
fi
@echo ""
@echo "Preflight check completed - ready to run ROCK admin server"

# Testing targets
test-unit: ## Run all unit tests
@echo "🧪 Running unit tests..."
@mkdir -p .tmp/test_data/logs
@uv run pytest tests/unit --timeout=60 --reruns 1 -v

test-integration: ## Run all integration tests in Docker (includes Ray + Docker + Admin)
@echo "🧪 Running integration tests in Docker..."
@./scripts/run-integration-tests.sh tests/integration
93 changes: 93 additions & 0 deletions scripts/run-integration-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash
# Run full integration tests inside a Docker container (Linux environment).
# This solves the issue where Ray cannot run stably on macOS (Apple Silicon).
#
# Usage:
# ./scripts/run-integration-tests.sh # Run all integration tests
# ./scripts/run-integration-tests.sh tests/unit # Run unit tests only
#
# Prerequisites:
# - Docker must be running (OrbStack / Docker Desktop)
# - python:3.11 image will be used as the base

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
TEST_PATH="${1:-tests/integration}"
CONTAINER_NAME="rock-test-runner-$$"
BASE_IMAGE="rock-test-base:latest"

echo "============================================"
echo " ROCK Integration Test Runner (Docker)"
echo "============================================"
echo ""

# Check Docker is available
if ! docker version > /dev/null 2>&1; then
echo "❌ Docker is not running. Please start Docker (OrbStack) first."
exit 1
fi
echo "✅ Docker is running"

# Build base image with Docker CLI + uv pre-installed (cached after first build)
if ! docker images "${BASE_IMAGE}" --format '{{.Repository}}' | grep -q rock-test-base; then
echo "📦 Building base test image (first time only, will be cached)..."
docker build -t "${BASE_IMAGE}" -f - . <<'DOCKERFILE'
FROM docker:cli AS docker-cli
FROM python:3.11
COPY --from=docker-cli /usr/local/bin/docker /usr/local/bin/docker
RUN pip install --no-cache-dir uv
DOCKERFILE
echo "✅ Base image built and cached"
else
echo "✅ Base image found (cached)"
fi
echo ""

echo "🚀 Starting test container..."
echo " Test path: ${TEST_PATH}"
echo ""

# Run tests inside a privileged container with Docker socket access.
# --privileged is needed for Docker-in-Docker (sandbox containers).
# Ray resources are set high enough to satisfy test requirements (CPU: 2, memory: 8GB).
docker run --rm \
--name "${CONTAINER_NAME}" \
--privileged \
-v "${PROJECT_ROOT}:/workspace" \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /workspace \
-e DOCKER_HOST=unix:///var/run/docker.sock \
-e UV_HTTP_TIMEOUT=120 \
--memory=16g \
--cpus=8 \
"${BASE_IMAGE}" bash -c "
set -e

echo '📦 Installing project dependencies...'
uv sync --all-extras --group test --quiet
echo '✅ Dependencies installed'

echo '⚡ Starting Ray cluster...'
uv run ray start --head --disable-usage-stats --num-cpus=8 --memory=17179869184
sleep 3

# Verify Ray is running
if uv run ray status > /dev/null 2>&1; then
echo '✅ Ray cluster is running'
else
echo '⚠️ Ray cluster may not be fully ready, proceeding anyway...'
fi

echo ''
echo '🧪 Running tests: ${TEST_PATH}'
echo '============================================'
mkdir -p .tmp/test_data/logs
uv run pytest ${TEST_PATH} -v --timeout=300 --reruns 1

echo ''
echo '🧹 Stopping Ray...'
uv run ray stop --force || true
echo '✅ Done!'
"
Loading