diff --git a/.github/workflows/_system_test.yml b/.github/workflows/_system_test.yml new file mode 100644 index 000000000..71a14ae84 --- /dev/null +++ b/.github/workflows/_system_test.yml @@ -0,0 +1,32 @@ +on: + workflow_call: + +env: + # https://github.com/pytest-dev/pytest/issues/2042 + PY_IGNORE_IMPORTMISMATCH: "1" + +jobs: + run: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + # Need this to get version number from last tag + fetch-depth: 0 + + - name: Install python packages + uses: ./.github/actions/install_requirements + + - name: Start RabbitMQ + uses: namoshek/rabbitmq-github-action@v1 + with: + ports: "61613:61613" + plugins: rabbitmq_stomp + + - name: Start Blueapi Server + run: blueapi -c ${{ github.workspace }}/tests/unit_tests/example_yaml/valid_stomp_config.yaml serve & + + - name: Run tests + run: tox -e system-test diff --git a/.github/workflows/_test.yml b/.github/workflows/_test.yml index 8fc0c8ee3..f652d4145 100644 --- a/.github/workflows/_test.yml +++ b/.github/workflows/_test.yml @@ -16,9 +16,6 @@ on: env: # https://github.com/pytest-dev/pytest/issues/2042 PY_IGNORE_IMPORTMISMATCH: "1" - BLUEAPI_TEST_STOMP_PORTS: "[61613,61614]" - - jobs: run: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 485b82b66..53f66b6d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,6 +34,11 @@ jobs: secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + system-test: + needs: check + if: needs.check.outputs.branch-pr == '' + uses: ./.github/workflows/_system_test.yml + container: needs: check if: needs.check.outputs.branch-pr == '' diff --git a/tests/system_tests/test_blueapi_system.py b/tests/system_tests/test_blueapi_system.py index 477a637c3..61656d253 100644 --- a/tests/system_tests/test_blueapi_system.py +++ b/tests/system_tests/test_blueapi_system.py @@ -5,6 +5,7 @@ import pytest from bluesky_stomp.models import BasicAuthentication from pydantic import TypeAdapter +from requests.exceptions import ConnectionError from blueapi.client.client import ( BlueapiClient, @@ -32,6 +33,13 @@ _DATA_PATH = Path(__file__).parent +_REQUIRES_AUTH_MESSAGE = """ +Authentication credentials are required to run this test. +The test has been skipped because authentication is currently disabled. +For more details, see: https://github.com/DiamondLightSource/blueapi/issues/676. +To enable and execute these tests, set `REQUIRES_AUTH=1` and provide valid credentials. +""" + # Step 1: Ensure a message bus that supports stomp is running and available: # src/script/start_rabbitmq.sh # @@ -43,7 +51,7 @@ @pytest.fixture -def client_without_auth(tmp_path) -> BlueapiClient: +def client_without_auth(tmp_path: Path) -> BlueapiClient: return BlueapiClient.from_config(config=ApplicationConfig(auth_token_path=tmp_path)) @@ -58,6 +66,20 @@ def client_with_stomp() -> BlueapiClient: ) +@pytest.fixture(scope="module", autouse=True) +def wait_for_server(): + client = BlueapiClient.from_config(config=ApplicationConfig()) + + for _ in range(20): + try: + client.get_environment() + return + except ConnectionError: + ... + time.sleep(0.5) + raise TimeoutError("No connection to the blueapi server") + + # This client will have auth enabled if it finds cached valid token @pytest.fixture def client() -> BlueapiClient: @@ -101,6 +123,7 @@ def clean_existing_tasks(client: BlueapiClient): yield +@pytest.mark.xfail(reason=_REQUIRES_AUTH_MESSAGE) def test_cannot_access_endpoints( client_without_auth: BlueapiClient, blueapi_client_get_methods: list[str] ): @@ -112,6 +135,7 @@ def test_cannot_access_endpoints( getattr(client_without_auth, get_method)() +@pytest.mark.xfail(reason=_REQUIRES_AUTH_MESSAGE) def test_can_get_oidc_config_without_auth(client_without_auth: BlueapiClient): assert client_without_auth.get_oidc_config() == OIDCConfig( well_known_url="https://example.com/realms/master/.well-known/openid-configuration",