|
@@ -20,9 +20,14 @@ from sentry.testutils.silo import region_silo_test
|
|
|
|
|
|
@region_silo_test(stable=True)
|
|
|
class MonitorTestCase(TestCase):
|
|
|
- def test_next_run_crontab_implicit(self):
|
|
|
+ def test_next_run_crontab(self):
|
|
|
ts = datetime(2019, 1, 1, 1, 10, 20, tzinfo=timezone.utc)
|
|
|
- monitor = Monitor(config={"schedule": "* * * * *"})
|
|
|
+ monitor = Monitor(
|
|
|
+ config={
|
|
|
+ "schedule_type": ScheduleType.CRONTAB,
|
|
|
+ "schedule": "* * * * *",
|
|
|
+ }
|
|
|
+ )
|
|
|
monitor_environment = MonitorEnvironment(monitor=monitor, last_checkin=ts)
|
|
|
|
|
|
# XXX: Seconds are removed as we clamp to the minute
|
|
@@ -41,23 +46,14 @@ class MonitorTestCase(TestCase):
|
|
|
2019, 1, 1, 1, 16, tzinfo=timezone.utc
|
|
|
)
|
|
|
|
|
|
- def test_next_run_latest_crontab_implicit(self):
|
|
|
- ts = datetime(2019, 1, 1, 1, 10, 20, tzinfo=timezone.utc)
|
|
|
- monitor = Monitor(config={"schedule": "* * * * *", "checkin_margin": 5})
|
|
|
- monitor_environment = MonitorEnvironment(monitor=monitor, last_checkin=ts)
|
|
|
-
|
|
|
- # XXX: Seconds are removed as we clamp to the minute
|
|
|
- assert monitor_environment.monitor.get_next_expected_checkin(ts) == datetime(
|
|
|
- 2019, 1, 1, 1, 11, tzinfo=timezone.utc
|
|
|
- )
|
|
|
- assert monitor_environment.monitor.get_next_expected_checkin_latest(ts) == datetime(
|
|
|
- 2019, 1, 1, 1, 16, tzinfo=timezone.utc
|
|
|
- )
|
|
|
-
|
|
|
- def test_next_run_crontab_explicit(self):
|
|
|
+ def test_next_run_latest_crontab_with_margin(self):
|
|
|
ts = datetime(2019, 1, 1, 1, 10, 20, tzinfo=timezone.utc)
|
|
|
monitor = Monitor(
|
|
|
- config={"schedule": "* * * * *", "schedule_type": ScheduleType.CRONTAB},
|
|
|
+ config={
|
|
|
+ "schedule_type": ScheduleType.CRONTAB,
|
|
|
+ "schedule": "* * * * *",
|
|
|
+ "checkin_margin": 5,
|
|
|
+ }
|
|
|
)
|
|
|
monitor_environment = MonitorEnvironment(monitor=monitor, last_checkin=ts)
|
|
|
|
|
@@ -65,18 +61,16 @@ class MonitorTestCase(TestCase):
|
|
|
assert monitor_environment.monitor.get_next_expected_checkin(ts) == datetime(
|
|
|
2019, 1, 1, 1, 11, tzinfo=timezone.utc
|
|
|
)
|
|
|
-
|
|
|
- monitor.config["schedule"] = "*/5 * * * *"
|
|
|
- assert monitor_environment.monitor.get_next_expected_checkin(ts) == datetime(
|
|
|
- 2019, 1, 1, 1, 15, tzinfo=timezone.utc
|
|
|
+ assert monitor_environment.monitor.get_next_expected_checkin_latest(ts) == datetime(
|
|
|
+ 2019, 1, 1, 1, 16, tzinfo=timezone.utc
|
|
|
)
|
|
|
|
|
|
- def test_next_run_crontab_explicit_timezone(self):
|
|
|
+ def test_next_run_crontab_with_timezone(self):
|
|
|
ts = datetime(2019, 1, 1, 1, 10, 20, tzinfo=timezone.utc)
|
|
|
monitor = Monitor(
|
|
|
config={
|
|
|
- "schedule": "0 12 * * *",
|
|
|
"schedule_type": ScheduleType.CRONTAB,
|
|
|
+ "schedule": "0 12 * * *",
|
|
|
"timezone": "UTC",
|
|
|
},
|
|
|
)
|
|
@@ -97,7 +91,10 @@ class MonitorTestCase(TestCase):
|
|
|
def test_next_run_interval(self):
|
|
|
ts = datetime(2019, 1, 1, 1, 10, 20, tzinfo=timezone.utc)
|
|
|
monitor = Monitor(
|
|
|
- config={"schedule": [1, "month"], "schedule_type": ScheduleType.INTERVAL},
|
|
|
+ config={
|
|
|
+ "schedule": [1, "month"],
|
|
|
+ "schedule_type": ScheduleType.INTERVAL,
|
|
|
+ },
|
|
|
)
|
|
|
monitor_environment = MonitorEnvironment(monitor=monitor, last_checkin=ts)
|
|
|
|