From 75d6cbf7296643b4f2e037f02799e6db53604480 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Tue, 6 Jan 2026 04:41:01 +0100 Subject: [PATCH] feat (backend): Add more performance tests (#11080) * Matmair/issue10740 (#497) * reduce noise in docker * refactor path infos * add more info during local frontend build * add frontend info during release build * Revert "Matmair/issue10740 (#497)" (#498) This reverts commit 415c52813bf6f3ab7e88d850d272686ad2910fb3. * add more performance tests (dummy) * dummy change * disable debug for a more realistic test * revert debug change * add "real" tests * fix style * specify backend for type check * add setup prep step * fix uninstall command * fix install? * fix instanciation * fix test * fix format * disable tests * add auth test * fix test --- .github/workflows/qc_checks.yaml | 12 ++++- src/backend/InvenTree/manage.py | 1 + src/performance/tests.py | 90 ++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 src/performance/tests.py diff --git a/.github/workflows/qc_checks.yaml b/.github/workflows/qc_checks.yaml index 8bf7bd8ab0..28d2a4dd1c 100644 --- a/.github/workflows/qc_checks.yaml +++ b/.github/workflows/qc_checks.yaml @@ -116,7 +116,7 @@ jobs: update: true - name: Check types run: | - ty check --python ${Python_ROOT_DIR}/bin/python3 + ty check --python ${Python_ROOT_DIR}/bin/python3 src/backend mkdocs: name: Style [Documentation] @@ -324,6 +324,16 @@ jobs: cd ${WRAPPER_NAME} invoke check-server coverage run -m unittest discover -s test/ + - name: Prepare environment for performance tests + run: | + pip uninstall pytest-django -y + cd ${WRAPPER_NAME} + pip install . + - name: Performance Reporting + uses: CodSpeedHQ/action@972e3437949c89e1357ebd1a2dbc852fcbc57245 # pin@v4 + with: + mode: simulation + run: pytest ./src/performance --codspeed coverage: name: Tests - DB [SQLite] + Coverage ${{ matrix.python_version }} diff --git a/src/backend/InvenTree/manage.py b/src/backend/InvenTree/manage.py index 988cd61e3f..9e1d7b6804 100755 --- a/src/backend/InvenTree/manage.py +++ b/src/backend/InvenTree/manage.py @@ -17,6 +17,7 @@ def main(): 'available on your PYTHONPATH environment variable? Did you ' 'forget to activate a virtual environment?' ) from exc + execute_from_command_line(sys.argv) diff --git a/src/performance/tests.py b/src/performance/tests.py new file mode 100644 index 0000000000..34930630a9 --- /dev/null +++ b/src/performance/tests.py @@ -0,0 +1,90 @@ +"""Performance benchmarking tests for InvenTree using the module.""" + +import json +import os + +import pytest +from inventree.api import InvenTreeAPI + +server = os.environ.get('INVENTREE_PYTHON_TEST_SERVER', 'http://127.0.0.1:12345') +user = os.environ.get('INVENTREE_PYTHON_TEST_USERNAME', 'testuser') +pwd = os.environ.get('INVENTREE_PYTHON_TEST_PASSWORD', 'testpassword') +api_client = InvenTreeAPI( + server, + username=user, + password=pwd, + timeout=30, + token_name='python-test', + use_token_auth=True, +) + + +@pytest.mark.benchmark +def test_api_auth_performance(): + """Benchmark the API authentication performance.""" + client = InvenTreeAPI( + server, + username=user, + password=pwd, + timeout=30, + token_name='python-test', + use_token_auth=True, + ) + assert client + + +@pytest.mark.benchmark +@pytest.mark.parametrize( + 'url', + [ + '/api/part/', + '/api/part/category/', + '/api/stock/', + '/api/stock/location/', + '/api/company/', + '/api/build/', + #'/api/build/line/', + '/api/build/item/', + '/api/order/so/', + '/api/order/so/shipment/', + #'/api/order/po/', + #'/api/order/po-line/', + '/api/user/roles/', + '/api/parameter/', + '/api/parameter/template/', + ], +) +def test_api_list_performance(url): + """Benchmark the API list request performance.""" + result = api_client.get(url) + assert result + assert len(result) > 0 + + +@pytest.mark.benchmark +@pytest.mark.parametrize( + 'url', + [ + '/api/part/', + '/api/part/category/', + '/api/stock/location/', + '/api/company/', + '/api/build/', + '/api/build/line/', + '/api/build/item/', + '/api/order/so/', + '/api/order/so/shipment/', + '/api/order/po/', + '/api/order/po-line/', + '/api/user/roles/', + '/api/parameter/', + '/api/parameter/template/', + ], +) +def test_api_options_performance(url): + """Benchmark the API OPTIONS request performance.""" + response = api_client.request(url, method='OPTIONS') + result = json.loads(response.text) + assert result + assert 'actions' in result + assert len(result['actions']) > 0