generated from astronomer/airflow-provider-sample
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from astronomer/fix_ci
Use hatch to run tests in CI - Remove the legacy CI - Runs tests with hatch - Enable static checks - Enable codecov - Fix test CI: https://github.com/astronomer/astro-provider-ray/actions/runs/10012466204/
- Loading branch information
Showing
12 changed files
with
149 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[run] | ||
omit = | ||
tests/* |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
name: test | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
Authorize: | ||
environment: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository && 'external' || 'internal' }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: true | ||
|
||
Static-Check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha || github.ref }} | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.11" | ||
architecture: "x64" | ||
- run: pip3 install hatch | ||
- run: hatch run tests.py3.11-2.9:static-check | ||
|
||
Run-Unit-Tests: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] | ||
airflow-version: ["2.7", "2.8", "2.9"] | ||
exclude: | ||
- python-version: "3.12" | ||
airflow-version: "2.7" | ||
- python-version: "3.12" | ||
airflow-version: "2.8" | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha || github.ref }} | ||
|
||
- uses: actions/cache@v4 | ||
with: | ||
path: | | ||
~/.cache/pip | ||
.nox | ||
key: unit-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.airflow-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('ray_provider/__init__.py') }} | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install packages and dependencies | ||
run: | | ||
python -m pip install hatch | ||
hatch -e tests.py${{ matrix.python-version }}-${{ matrix.airflow-version }} run pip freeze | ||
- name: Test Ray against Airflow ${{ matrix.airflow-version }} and Python ${{ matrix.python-version }} | ||
run: | | ||
hatch run tests.py${{ matrix.python-version }}-${{ matrix.airflow-version }}:test-cov | ||
- name: Upload coverage to Github | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: coverage-unit-test-${{ matrix.python-version }}-${{ matrix.airflow-version }} | ||
path: .coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
asend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
AIRFLOW_VERSION="$1" | ||
PYTHON_VERSION="$2" | ||
|
||
CONSTRAINT_URL="https://raw.githubusercontent.com/apache/airflow/constraints-$AIRFLOW_VERSION.0/constraints-$PYTHON_VERSION.txt" | ||
curl -sSL $CONSTRAINT_URL -o /tmp/constraint.txt | ||
# Workaround to remove PyYAML constraint that will work on both Linux and MacOS | ||
sed '/PyYAML==/d' /tmp/constraint.txt > /tmp/constraint.txt.tmp | ||
mv /tmp/constraint.txt.tmp /tmp/constraint.txt | ||
# Install Airflow with constraints | ||
pip install apache-airflow==$AIRFLOW_VERSION --constraint /tmp/constraint.txt | ||
pip install pydantic --constraint /tmp/constraint.txt | ||
rm /tmp/constraint.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pytest \ | ||
-vv \ | ||
--cov=ray_provider \ | ||
--cov-report=term-missing \ | ||
--cov-report=xml \ | ||
--durations=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pytest \ | ||
-vv \ | ||
--durations=0 \ | ||
-m "not (integration or perf)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,39 @@ | ||
import time | ||
from unittest import mock | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from airflow.triggers.base import TriggerEvent | ||
from ray.dashboard.modules.job.sdk import JobStatus, JobSubmissionClient | ||
from ray.dashboard.modules.job.sdk import JobStatus | ||
|
||
from ray_provider.triggers.ray import RayJobTrigger | ||
|
||
|
||
class TestRayJobTrigger: | ||
|
||
@pytest.mark.asyncio | ||
async def test_run_no_job_id(self): | ||
trigger = RayJobTrigger(job_id="", host="localhost", end_time=time.time() + 60, poll_interval=1) | ||
@patch("ray_provider.triggers.ray.RayJobTrigger._is_terminal_state") | ||
@patch("ray_provider.triggers.ray.RayJobTrigger.hook") | ||
async def test_run_no_job_id(self, mock_hook, mock_is_terminal): | ||
mock_is_terminal.return_value = True | ||
trigger = RayJobTrigger(job_id="", poll_interval=1, conn_id="test", xcom_dashboard_url="test") | ||
|
||
generator = trigger.run() | ||
event = await generator.send(None) | ||
assert event == TriggerEvent( | ||
{"status": "error", "message": "No job_id provided to async trigger", "job_id": ""} | ||
) | ||
event = await generator.asend(None) | ||
assert event == TriggerEvent({"status": "error", "message": "Job run has failed.", "job_id": ""}) | ||
|
||
@pytest.mark.asyncio | ||
async def test_run_job_succeeded(self): | ||
trigger = RayJobTrigger(job_id="test_job_id", host="localhost", end_time=time.time() + 60, poll_interval=1) | ||
|
||
client_mock = mock.MagicMock(spec=JobSubmissionClient) | ||
client_mock.get_job_status.return_value = JobStatus.SUCCEEDED | ||
|
||
async def async_generator(): | ||
yield "log line 1" | ||
yield "log line 2" | ||
|
||
client_mock.tail_job_logs.return_value = async_generator() | ||
|
||
with mock.patch("ray_provider.triggers.kuberay.JobSubmissionClient", return_value=client_mock): | ||
generator = trigger.run() | ||
async for event in generator: | ||
assert event == TriggerEvent( | ||
{ | ||
"status": "success", | ||
"message": "Job run test_job_id has completed successfully.", | ||
"job_id": "test_job_id", | ||
} | ||
) | ||
break # Stop after the first event for testing purposes | ||
@patch("ray_provider.triggers.ray.RayJobTrigger.hook") | ||
async def test_run_job_succeeded(self, mock_hook): | ||
trigger = RayJobTrigger(job_id="test_job_id", poll_interval=1, conn_id="test", xcom_dashboard_url="test") | ||
|
||
mock_hook.get_ray_job_status.return_value = JobStatus.SUCCEEDED | ||
|
||
generator = trigger.run() | ||
async for event in generator: | ||
assert event == TriggerEvent( | ||
{ | ||
"status": "success", | ||
"message": "Job run test_job_id has completed successfully.", | ||
"job_id": "test_job_id", | ||
} | ||
) | ||
break # Stop after the first event for testing purposes |