Skip to content

Commit 909b5a6

Browse files
authored
Add system test CI job, add tests which talk to central service (#138)
* Let some system tests talk to deployed server * Add tox commands * Run system tests in CI * Adjust docs
1 parent de81d49 commit 909b5a6

File tree

5 files changed

+88
-8
lines changed

5 files changed

+88
-8
lines changed

.github/workflows/_test_system.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
python-version:
5+
type: string
6+
description: The version of python to install
7+
required: true
8+
runs-on:
9+
type: string
10+
description: The runner to run this job on
11+
required: true
12+
secrets:
13+
CODECOV_TOKEN:
14+
required: true
15+
16+
env:
17+
# https://github.com/pytest-dev/pytest/issues/2042
18+
PY_IGNORE_IMPORTMISMATCH: "1"
19+
20+
jobs:
21+
run:
22+
runs-on: ${{ inputs.runs-on }}
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
with:
28+
# Need this to get version number from last tag
29+
fetch-depth: 0
30+
31+
- if: inputs.python-version == 'dev'
32+
name: Install dev versions of python packages
33+
uses: ./.github/actions/install_requirements
34+
35+
- if: inputs.python-version != 'dev'
36+
name: Install latest versions of python packages
37+
uses: ./.github/actions/install_requirements
38+
with:
39+
python-version: ${{ inputs.python-version }}
40+
pip-install: ".[dev,server]"
41+
42+
- name: Deploy local server
43+
run: ./deployment/build_and_push.sh -r -b
44+
45+
- name: Run system tests
46+
run: tox -e system_tests_local

.github/workflows/ci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,25 @@ jobs:
3434
secrets:
3535
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
3636

37+
test_system:
38+
needs: check
39+
if: needs.check.outputs.branch-pr == ''
40+
strategy:
41+
matrix:
42+
runs-on: ["ubuntu-latest"] # can add windows-latest, macos-latest
43+
python-version: ["3.11", "3.12", "3.13"]
44+
include:
45+
# Include one that runs in the dev environment
46+
- runs-on: "ubuntu-latest"
47+
python-version: "dev"
48+
fail-fast: false
49+
uses: ./.github/workflows/_test_system.yml
50+
with:
51+
runs-on: ${{ matrix.runs-on }}
52+
python-version: ${{ matrix.python-version }}
53+
secrets:
54+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
55+
3756
container:
3857
needs: check
3958
if: needs.check.outputs.branch-pr == ''

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ To run unit tests, type `tox -e unit_tests` from within the dev container
3333

3434
There is a convenient script in `./deployment/build_and_push.sh` which can be used to easily build and run the container locally for testing, and optionally push the container to ghcr. In general we should rely on the CI to be pushing new containers - it should only be done manually for urgent debugging.
3535

36-
To run system tests, start a local container by running `./deployment/build_and_push.sh -r -b`. Then, in the dev container, forward port 8555. There are instructions on port forwarding within vscode [here](https://code.visualstudio.com/docs/debugtest/port-forwarding). Next, in a terminal in the devcontainer, run `pytest .` from the `daq-config-server` directory.
36+
To run local system tests, start a local container by running `./deployment/build_and_push.sh -r -b`. Then, in the dev container, forward port 8555. There are instructions on port forwarding within vscode [here](https://code.visualstudio.com/docs/debugtest/port-forwarding). Next, in a terminal in the devcontainer, run `tox -e system_tests_local` from the `daq-config-server` directory.
3737

3838
To test on argus, log in to argus in your namespace and run:
3939

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ addopts = """
7575
"""
7676
markers = """
7777
requires_local_server: mark a test which requires locally hosting the config server
78+
requires_deployed_server: mark a test which requires talking to the deployed config server
7879
use_threading: mark a test which will kickoff the background thread in WhitelistFetcher
7980
"""
8081

@@ -101,7 +102,7 @@ legacy_tox_ini = """
101102
[tox]
102103
skipsdist=True
103104
104-
[testenv:{pre-commit,type-checking,unit_tests,docs,system_tests}]
105+
[testenv:{pre-commit,type-checking,unit_tests,docs,system_tests, system_tests_local, system_tests_deployed}]
105106
# Don't create a virtualenv for the command, requires tox-direct plugin
106107
direct = True
107108
passenv = *
@@ -117,6 +118,8 @@ commands =
117118
unit_tests: pytest --cov=daq_config_server --cov-report term --cov-report xml:cov.xml {posargs} tests/unit_tests
118119
docs: sphinx-{posargs:build -EW --keep-going} -T docs build/html
119120
system_tests: pytest tests/system_tests
121+
system_tests_local: pytest tests/system_tests -m requires_local_server
122+
system_tests_deployed: pytest tests/system_tests -m requires_deployed_server
120123
"""
121124

122125
[tool.ruff]

tests/system_tests/test_client.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
)
2121

2222
SERVER_ADDRESS = "http://0.0.0.0:8555"
23+
DEPLOYED_SERVER_ADDRESS = "https://daq-config.diamond.ac.uk"
2324

2425
# Docs for running these system tests will be added in https://github.com/DiamondLightSource/daq-config-server/issues/68
2526

@@ -29,6 +30,11 @@ def server():
2930
return ConfigServer(SERVER_ADDRESS)
3031

3132

33+
@pytest.fixture
34+
def deployed_server():
35+
return ConfigServer(DEPLOYED_SERVER_ADDRESS)
36+
37+
3238
@pytest.mark.requires_local_server
3339
def test_read_unformatted_file_as_plain_text(server: ConfigServer):
3440
with open(TestDataPaths.TEST_BEAMLINE_PARAMETERS_PATH) as f:
@@ -144,23 +150,29 @@ def test_request_for_file_with_converter_with_wrong_pydantic_model_errors(
144150
server.get_file_contents(ServerFilePaths.GOOD_LUT, DisplayConfig)
145151

146152

147-
@pytest.mark.requires_local_server
148-
def test_all_files_in_file_converter_map_can_be_converted_to_dict(server: ConfigServer):
153+
@pytest.mark.requires_deployed_server
154+
def test_all_files_in_file_converter_map_can_be_converted_to_dict(
155+
deployed_server: ConfigServer,
156+
):
149157
for filename in file_converter_map.FILE_TO_CONVERTER_MAP.keys():
150-
result = server.get_file_contents(filename, dict)
158+
if filename.startswith("/tests/test_data/"):
159+
continue
160+
result = deployed_server.get_file_contents(filename, dict)
151161
assert isinstance(result, dict)
152162

153163

154-
@pytest.mark.requires_local_server
164+
@pytest.mark.requires_deployed_server
155165
def test_all_files_in_file_converter_map_can_be_converted_to_target_type(
156-
server: ConfigServer,
166+
deployed_server: ConfigServer,
157167
):
158168
with patch(
159169
"daq_config_server.converters._file_converter_map.xmltodict.parse.__annotations__",
160170
{"return": dict}, # Force a return type for xmltodict.parse()
161171
):
162172
for filename, converter in file_converter_map.FILE_TO_CONVERTER_MAP.items():
173+
if filename.startswith("/tests/test_data/"):
174+
continue
163175
return_type = get_type_hints(converter)["return"]
164176
assert return_type is dict or issubclass(return_type, ConfigModel)
165-
result = server.get_file_contents(filename, return_type)
177+
result = deployed_server.get_file_contents(filename, return_type)
166178
assert isinstance(result, return_type)

0 commit comments

Comments
 (0)