mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-29 04:51:11 +00:00
Moves query logger duration into pytest.ini file
This commit is contained in:
parent
cc7250770c
commit
26b6699b26
2 changed files with 7 additions and 1 deletions
|
@ -1,5 +1,10 @@
|
||||||
""" Log query runtimes for testing """
|
""" Log query runtimes for testing """
|
||||||
import time
|
import time
|
||||||
|
from environs import Env
|
||||||
|
|
||||||
|
env = Env()
|
||||||
|
env.read_env()
|
||||||
|
MAX_QUERY_DURATION = float(env("MAX_QUERY_DURATION"))
|
||||||
|
|
||||||
|
|
||||||
class QueryLogger:
|
class QueryLogger:
|
||||||
|
@ -30,7 +35,7 @@ class QueryLogger:
|
||||||
self.queries.append(current_query)
|
self.queries.append(current_query)
|
||||||
|
|
||||||
|
|
||||||
def raise_long_query_runtime(queries, threshold=0.0006):
|
def raise_long_query_runtime(queries, threshold=MAX_QUERY_DURATION):
|
||||||
"""Raises an exception if any query took longer than the threshold"""
|
"""Raises an exception if any query took longer than the threshold"""
|
||||||
for query in queries:
|
for query in queries:
|
||||||
if query["duration"] > threshold:
|
if query["duration"] > threshold:
|
||||||
|
|
|
@ -28,3 +28,4 @@ env =
|
||||||
EMAIL_HOST_PASSWORD =
|
EMAIL_HOST_PASSWORD =
|
||||||
EMAIL_USE_TLS = true
|
EMAIL_USE_TLS = true
|
||||||
ENABLE_PREVIEW_IMAGES = false
|
ENABLE_PREVIEW_IMAGES = false
|
||||||
|
MAX_QUERY_DURATION = 0.005
|
||||||
|
|
Loading…
Reference in a new issue