2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-01-07 19:58:00 +00:00

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 415c52813b.

* 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
This commit is contained in:
Matthias Mair
2026-01-06 04:41:01 +01:00
committed by GitHub
parent 97ea76a955
commit 75d6cbf729
3 changed files with 102 additions and 1 deletions

View File

@@ -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 }}

View File

@@ -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)

90
src/performance/tests.py Normal file
View File

@@ -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