tests: make report generation time limit configurable

This commit is contained in:
Nicola Tarocco 2024-02-26 11:28:24 +01:00
parent d1555d77fc
commit ddfe0b660e
No known key found for this signature in database
GPG key ID: A08DEF00BA54E806
7 changed files with 17 additions and 17 deletions

View file

@ -12,7 +12,6 @@ include:
variables:
project_name: caimira
PY_VERSION: "3.9"
# ###################################################################################################
@ -110,7 +109,7 @@ check_openshift_config_prod:
- /kaniko/executor --context ${CI_PROJECT_DIR}/${DOCKER_CONTEXT_DIRECTORY} --dockerfile ${CI_PROJECT_DIR}/${DOCKERFILE_DIRECTORY}/Dockerfile --destination ${CI_REGISTRY_IMAGE}/${IMAGE_NAME}:${IMAGE_TAG}
# Print the full registry path of the pushed image
- echo "Image pushed successfully to ${CI_REGISTRY_IMAGE}/${IMAGE_NAME}:${IMAGE_TAG}"
auth-service-image_builder:
extends:

View file

@ -156,9 +156,7 @@ pytest ./caimira
### Running the profiler
The profiler is enabled in one of the following cases:
- the calculator app is running in `debug` mode
- the environment variable `CAIMIRA_PROFILER_ENABLED` is set to 1
The profiler is enabled when the environment variable `CAIMIRA_PROFILER_ENABLED` is set to 1.
When visiting http://localhost:8080/profiler, you can start a new session and choose between [PyInstrument](https://github.com/joerick/pyinstrument) or [cProfile](https://docs.python.org/3/library/profile.html#module-cProfile). The app includes two different profilers, mainly because they can give different information.

View file

@ -284,7 +284,7 @@
key: ARVE_API_KEY
name: arve-api
- name: DATA_SERVICE_ENABLED
value: 'False'
value: 'True'
image: '${PROJECT_NAME}/calculator-app'
ports:
- containerPort: 8080
@ -363,7 +363,7 @@
- name: CAIMIRA_CALCULATOR_PREFIX
value: /calculator-open
- name: DATA_SERVICE_ENABLED
value: 'False'
value: 'True'
image: '${PROJECT_NAME}/calculator-app'
ports:
- containerPort: 8080

View file

@ -516,8 +516,8 @@ def make_app(
'filename': 'userguide.html.j2'}),
]
profiler = os.environ.get('CAIMIRA_PROFILER_ENABLED', 0)
if debug or profiler:
profiler_enabled = os.environ.get('CAIMIRA_PROFILER_ENABLED', 0)
if profiler_enabled:
urls += [
(get_root_url(CaimiraProfiler.ROOT_URL), ProfilerPage),
(get_root_url(r'{root_url}/(.*)'.format(root_url=CaimiraProfiler.ROOT_URL)), ProfilerReport),

View file

@ -195,6 +195,10 @@ class CaimiraProfiler:
@property
def is_active(self):
"""Return True if a session is active."""
enabled = os.environ.get("CAIMIRA_PROFILER_ENABLED", 0)
if not enabled:
return False
if not os.path.exists(self._cache_filepath):
return False

View file

@ -1,8 +1,8 @@
import concurrent.futures
from functools import partial
import os
import time
import numpy.testing
import numpy as np
import pytest
@ -16,7 +16,7 @@ def test_generate_report(baseline_form) -> None:
# generate a report for it. Because this is what happens in the caimira
# calculator, we confirm that the generation happens within a reasonable
# time threshold.
time_limit: float = 20.0 # seconds
time_limit: float = float(os.environ.get("CAIMIRA_TESTS_CALCULATOR_TIMEOUT", 10.))
start = time.perf_counter()
@ -25,6 +25,8 @@ def test_generate_report(baseline_form) -> None:
concurrent.futures.ThreadPoolExecutor, 1,
))
end = time.perf_counter()
total = end-start
print(f"Time limit: {time_limit} | Time taken: {end} - {start} = {total} < {time_limit}")
assert report != ""
assert end - start < time_limit

View file

@ -1,13 +1,13 @@
import os
from pathlib import Path
import pytest
import tornado.testing
from retry import retry
import caimira.apps.calculator
from caimira.apps.calculator.report_generator import generate_permalink
_TIMEOUT = 20.
_TIMEOUT = float(os.environ.get("CAIMIRA_TESTS_CALCULATOR_TIMEOUT", 10.))
@pytest.fixture
@ -34,7 +34,6 @@ async def test_404(http_server_client):
assert resp.code == 404
@retry(tries=10)
class TestBasicApp(tornado.testing.AsyncHTTPTestCase):
def get_app(self):
return caimira.apps.calculator.make_app()
@ -63,7 +62,6 @@ class TestBasicApp(tornado.testing.AsyncHTTPTestCase):
assert 'expected number of new cases is' in response.body.decode()
@retry(tries=10)
class TestCernApp(tornado.testing.AsyncHTTPTestCase):
def get_app(self):
cern_theme = Path(caimira.apps.calculator.__file__).parent.parent / 'themes' / 'cern'
@ -76,7 +74,6 @@ class TestCernApp(tornado.testing.AsyncHTTPTestCase):
assert 'expected number of new cases is' in response.body.decode()
retry(tries=10)
class TestOpenApp(tornado.testing.AsyncHTTPTestCase):
def get_app(self):
return caimira.apps.calculator.make_app(calculator_prefix="/mycalc")
@ -149,7 +146,7 @@ class TestCERNGenericPage(tornado.testing.AsyncHTTPTestCase):
]
return tornado.web.Application(pages, **app.settings)
@tornado.testing.gen_test(timeout=_TIMEOUT)
def test_user_guide(self):
response = yield self.http_client.fetch(self.get_url('/calculator/user-guide'))