Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions services/web/server/tests/unit/isolated/test_security_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# pylint: disable=unused-variable
# pylint: disable=too-many-arguments

import asyncio
import statistics
import time
from collections import OrderedDict
from collections.abc import Awaitable, Callable
from typing import Any
Expand Down Expand Up @@ -414,13 +414,13 @@ async def test_time_overhead_on_handlers_of_auth_decorators(
get_active_user_or_none_dbmock: MagicMock,
is_user_in_product_name_dbmock: MagicMock,
):
async def _req(url_):
start = asyncio.get_event_loop().time()
async def _req(url_: str) -> int:
start_ns = time.perf_counter_ns()
resp = await client.post(url_)
stop = asyncio.get_event_loop().time()
elapsed_ns = time.perf_counter_ns() - start_ns

assert resp.ok, f"error: {await resp.text()}"
return stop - start
return elapsed_ns

num_of_rounds = 100
public_elapsed_times = [await _req("/v0/public") for _ in range(num_of_rounds)]
Expand All @@ -429,11 +429,12 @@ async def _req(url_):
# SEE https://docs.python.org/3/library/statistics.html#function-details
# Note The mean is strongly affected by outliers and is not necessarily a typical example of the data points.
# For a more robust, although less efficient, measure of central tendency, see median().
ref_elapsed = statistics.median(public_elapsed_times)
elapsed = statistics.median(admin_elapsed_times)
ref_elapsed_ns = statistics.median(public_elapsed_times)
elapsed_ns = statistics.median(admin_elapsed_times)
elapsed_ratio = elapsed_ns / max(ref_elapsed_ns, 1)

# NOTE: 150% more wrt reference (basically ~ 2.5x more !!!!!!!!!!!)
# and this is mocking the access to the database!
msg = f"got {elapsed/ref_elapsed=} from medians {elapsed=} and {ref_elapsed=} after {num_of_rounds=}"
msg = f"got {elapsed_ratio=} from medians {elapsed_ns=}ns and {ref_elapsed_ns=}ns after {num_of_rounds=}"
Comment thread
GitHK marked this conversation as resolved.
print(msg.capitalize())
assert elapsed < ref_elapsed * (1 + 1.6), msg
assert elapsed_ns < ref_elapsed_ns * (1 + 1.6), msg
Loading