From dfcf7aafbed2e3171fe0dfcab7ed1f7436f9dd0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Thu, 31 May 2018 11:55:29 +0300 Subject: [PATCH] Check.in_grace_period() looks at `last_ping_was_fail` flag. --- hc/api/models.py | 3 +++ hc/api/tests/test_check_model.py | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/hc/api/models.py b/hc/api/models.py index a71b81b0..414d2824 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -146,6 +146,9 @@ class Check(models.Model): if self.status in ("new", "paused"): return False + if self.last_ping_was_fail: + return False + grace_start = self.get_grace_start() grace_end = grace_start + self.grace return grace_start < timezone.now() < grace_end diff --git a/hc/api/tests/test_check_model.py b/hc/api/tests/test_check_model.py index 0f28b346..a5ab9e54 100644 --- a/hc/api/tests/test_check_model.py +++ b/hc/api/tests/test_check_model.py @@ -20,6 +20,16 @@ class CheckModelTestCase(TestCase): check = Check() self.assertFalse(check.in_grace_period()) + def test_in_grace_period_handles_fail_ping(self): + check = Check() + check.status = "up" + check.last_ping = timezone.now() - timedelta(days=1, minutes=30) + check.last_ping_was_fail = True + + # If last ping was signalling a failure, we're not in grace period, + # we're down + self.assertFalse(check.in_grace_period()) + def test_status_works_with_grace_period(self): check = Check() check.status = "up"