Skip to content

Commit 5006b77

Browse files
committed
👷
1 parent 4a5f36f commit 5006b77

File tree

8 files changed

+101
-28
lines changed

8 files changed

+101
-28
lines changed

.github/workflows/ci.yml

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,28 +89,47 @@ jobs:
8989

9090
benchmarks:
9191
name: Run benchmarks
92-
runs-on: ubuntu-latest
92+
runs-on: codspeed-macro
93+
94+
services:
95+
postgres:
96+
image: postgis/postgis:17-3.5
97+
env:
98+
POSTGRES_HOST_AUTH_METHOD: trust
99+
ports:
100+
- 5432:5432
101+
# needed because the postgres container does not provide a healthcheck
102+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
103+
93104
steps:
94105
- uses: actions/checkout@v4
95-
- name: Bring up docker compose and load data
96-
run: |
97-
docker compose up -d --build || ( docker compose logs >&2 && exit 1; )
98-
until docker compose logs web | grep -q "spawned uWSGI worker"; do
99-
echo "uWSGI not running yet, waiting..."
100-
sleep 3
101-
done
102-
docker compose exec --user root web pip install factory-boy
103-
cat performance_test/create_data.py | docker compose exec -T web src/manage.py shell
104-
105-
- name: Install dependencies
106-
run: |
107-
pip install -r requirements/ci.txt
106+
# - name: Bring up docker compose and load data
107+
# run: |
108+
# docker compose up -d --build || ( docker compose logs >&2 && exit 1; )
109+
# until docker compose logs web | grep -q "spawned uWSGI worker"; do
110+
# echo "uWSGI not running yet, waiting..."
111+
# sleep 3
112+
# done
113+
# docker compose exec --user root web pip install factory-boy
114+
# cat performance_test/create_data.py | docker compose exec -T web src/manage.py shell
115+
116+
- name: Set up backend environment
117+
uses: maykinmedia/[email protected]
118+
with:
119+
apt-packages: 'libgdal-dev gdal-bin'
120+
python-version: '3.11'
121+
setup-node: true
108122

109123
- name: Run benchmarks
110-
uses: CodSpeedHQ/action@v3
124+
uses: CodSpeedHQ/action@v3.5.0
111125
with:
112126
token: ${{ secrets.CODSPEED_TOKEN }}
113127
run: "pytest performance_test/ --codspeed"
128+
env:
129+
DJANGO_SETTINGS_MODULE: objects.conf.ci
130+
SECRET_KEY: dummy
131+
DB_USER: postgres
132+
DB_PASSWORD: ''
114133

115134
docs:
116135
runs-on: ubuntu-latest

performance_test/conftest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import pytest
2+
3+
from objects.core.tests.factories import ObjectRecordFactory, ObjectTypeFactory
4+
from objects.token.tests.factories import TokenAuthFactory
5+
6+
7+
@pytest.fixture(scope="session")
8+
def setup(django_db_setup, django_db_blocker):
9+
print("setup")
10+
with django_db_blocker.unblock():
11+
object_type = ObjectTypeFactory.create(
12+
service__api_root="http://localhost:8001/api/v2/",
13+
uuid="f1220670-8ab7-44f1-a318-bd0782e97662",
14+
)
15+
16+
TokenAuthFactory(token="secret", is_superuser=True)
17+
18+
ObjectRecordFactory.create_batch(
19+
5000,
20+
object__object_type=object_type,
21+
start_at="2020-01-01",
22+
version=1,
23+
data={"kiemjaar": "1234"},
24+
)

performance_test/test_objects_list.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import requests
1+
import pytest
22
from furl import furl
33

44
BASE_URL = furl("http://localhost:8000/api/v2/")
55
AUTH_HEADERS = {"Authorization": "Token secret"}
66

77

8-
def test_objects_api_list(benchmark):
8+
@pytest.mark.django_db
9+
def test_objects_api_list(benchmark, client, setup):
910
"""
1011
Regression test for maykinmedia/objects-api#538
1112
"""
@@ -17,9 +18,9 @@ def test_objects_api_list(benchmark):
1718
}
1819

1920
def make_request():
20-
return requests.get((BASE_URL / "objects").set(params), headers=AUTH_HEADERS)
21+
return client.get((BASE_URL / "objects").set(params), headers=AUTH_HEADERS)
2122

22-
result = benchmark(make_request)
23+
response = benchmark(make_request)
2324

24-
assert result.status_code == 200
25-
assert result.json()["count"] == 5000
25+
assert response.status_code == 200
26+
assert response.json()["count"] == 5000

requirements/base.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ certifi==2024.7.4
4141
# elastic-apm
4242
# requests
4343
# sentry-sdk
44-
cffi==1.16.0
44+
cffi==1.17.1
4545
# via cryptography
4646
charset-normalizer==3.3.2
4747
# via requests

requirements/ci.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ certifi==2024.7.4
7979
# elastic-apm
8080
# requests
8181
# sentry-sdk
82-
cffi==1.16.0
82+
cffi==1.17.1
8383
# via
8484
# -c requirements/base.txt
8585
# -r requirements/base.txt
@@ -461,6 +461,8 @@ kombu==5.4.2
461461
# celery
462462
lxml==4.9.4
463463
# via pyquery
464+
markdown-it-py==3.0.0
465+
# via rich
464466
markupsafe==2.1.3
465467
# via
466468
# -c requirements/base.txt
@@ -473,6 +475,8 @@ maykin-2fa==1.0.1
473475
# open-api-framework
474476
mccabe==0.7.0
475477
# via flake8
478+
mdurl==0.1.2
479+
# via markdown-it-py
476480
mozilla-django-oidc==4.0.0
477481
# via
478482
# -c requirements/base.txt
@@ -564,6 +568,7 @@ pyflakes==3.2.0
564568
# via flake8
565569
pygments==2.18.0
566570
# via
571+
# rich
567572
# sphinx
568573
# sphinx-tabs
569574
pyjwt==2.4.0
@@ -590,7 +595,10 @@ pytest==8.3.3
590595
# via
591596
# -r requirements/test-tools.in
592597
# pytest-codspeed
593-
pytest-codspeed==2.2.1
598+
# pytest-django
599+
pytest-codspeed==3.0.0
600+
# via -r requirements/test-tools.in
601+
pytest-django==4.10.0
594602
# via -r requirements/test-tools.in
595603
python-dateutil==2.9.0.post0
596604
# via
@@ -656,6 +664,8 @@ requests-mock==1.12.1
656664
# -r requirements/base.txt
657665
# -r requirements/test-tools.in
658666
# commonground-api-common
667+
rich==13.9.4
668+
# via pytest-codspeed
659669
ruamel-yaml==0.18.10
660670
# via
661671
# -c requirements/base.txt

requirements/dev.txt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ certifi==2024.7.4
102102
# httpx
103103
# requests
104104
# sentry-sdk
105-
cffi==1.16.0
105+
cffi==1.17.1
106106
# via
107107
# -c requirements/ci.txt
108108
# -r requirements/ci.txt
@@ -541,7 +541,10 @@ lxml==4.9.4
541541
# -r requirements/ci.txt
542542
# pyquery
543543
markdown-it-py==3.0.0
544-
# via rich
544+
# via
545+
# -c requirements/ci.txt
546+
# -r requirements/ci.txt
547+
# rich
545548
markupsafe==2.1.3
546549
# via
547550
# -c requirements/ci.txt
@@ -558,7 +561,10 @@ mccabe==0.7.0
558561
# -r requirements/ci.txt
559562
# flake8
560563
mdurl==0.1.2
561-
# via markdown-it-py
564+
# via
565+
# -c requirements/ci.txt
566+
# -r requirements/ci.txt
567+
# markdown-it-py
562568
mozilla-django-oidc==4.0.0
563569
# via
564570
# -c requirements/ci.txt
@@ -718,7 +724,12 @@ pytest==8.3.3
718724
# -c requirements/ci.txt
719725
# -r requirements/ci.txt
720726
# pytest-codspeed
721-
pytest-codspeed==2.2.1
727+
# pytest-django
728+
pytest-codspeed==3.0.0
729+
# via
730+
# -c requirements/ci.txt
731+
# -r requirements/ci.txt
732+
pytest-django==4.10.0
722733
# via
723734
# -c requirements/ci.txt
724735
# -r requirements/ci.txt
@@ -792,7 +803,10 @@ requests-mock==1.12.1
792803
# commonground-api-common
793804
rich==13.9.4
794805
# via
806+
# -c requirements/ci.txt
807+
# -r requirements/ci.txt
795808
# bump-my-version
809+
# pytest-codspeed
796810
# rich-click
797811
rich-click==1.8.5
798812
# via bump-my-version

requirements/test-tools.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Dependencies only relevant for (unit) testing
55
codecov
66
pytest
7+
pytest-django
78
pytest-codspeed
89
coverage < 5.0
910
django-webtest

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ skip_glob = **/migrations/**
1414
known_django=django
1515
known_first_party=objects
1616
sections=FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
17+
18+
[tool:pytest]
19+
DJANGO_SETTINGS_MODULE = objects.conf.ci
20+
pythonpath = . src

0 commit comments

Comments
 (0)