Skip to content

Commit

Permalink
Improve too_slow healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Jun 15, 2022
1 parent c10559a commit b648264
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions hypothesis-python/RELEASE.rst
@@ -0,0 +1,4 @@
RELEASE_TYPE: patch

This patch makes the :obj:`~hypothesis.HealthCheck.too_slow` health check more
consistent with long :obj:`~hypothesis.settings.deadline` tests (:issue:`3367`)
Expand Up @@ -13,6 +13,7 @@
import time
from collections import defaultdict
from contextlib import contextmanager
from datetime import timedelta
from enum import Enum
from random import Random, getrandbits
from weakref import WeakKeyDictionary
Expand Down Expand Up @@ -386,7 +387,10 @@ def record_for_health_check(self, data):

draw_time = sum(state.draw_times)

if draw_time > 1.0:
# Allow at least the greater of one second or 5x the deadline. If deadline
# is None, allow 30s - the user can disable the healthcheck too if desired.
draw_time_limit = 5 * (self.settings.deadline or timedelta(seconds=6))
if draw_time > max(1.0, draw_time_limit.total_seconds()):
fail_health_check(
self.settings,
"Data generation is extremely slow: Only produced "
Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/tests/cover/test_health_checks.py
Expand Up @@ -45,7 +45,7 @@ def test(x):


def test_slow_generation_inline_fails_a_health_check():
@settings(HEALTH_CHECK_SETTINGS, deadline=None)
@HEALTH_CHECK_SETTINGS
@given(st.data())
def test(data):
data.draw(st.integers().map(lambda x: time.sleep(0.2)))
Expand Down

0 comments on commit b648264

Please sign in to comment.