|
15 | 15 | crons_task_retry, |
16 | 16 | crons_task_success, |
17 | 17 | ) |
18 | | -from sentry_sdk.integrations.celery.utils import _get_humanized_interval |
19 | 18 |
|
20 | 19 |
|
21 | 20 | def test_get_headers(): |
@@ -52,25 +51,6 @@ def test_get_headers(): |
52 | 51 | assert _get_headers(fake_task) == {"bla": "blub", "tri": "blub", "bar": "baz"} |
53 | 52 |
|
54 | 53 |
|
55 | | -@pytest.mark.parametrize( |
56 | | - "seconds, expected_tuple", |
57 | | - [ |
58 | | - (0, (0, "second")), |
59 | | - (1, (1, "second")), |
60 | | - (0.00001, (0, "second")), |
61 | | - (59, (59, "second")), |
62 | | - (60, (1, "minute")), |
63 | | - (100, (1, "minute")), |
64 | | - (1000, (16, "minute")), |
65 | | - (10000, (2, "hour")), |
66 | | - (100000, (1, "day")), |
67 | | - (100000000, (1157, "day")), |
68 | | - ], |
69 | | -) |
70 | | -def test_get_humanized_interval(seconds, expected_tuple): |
71 | | - assert _get_humanized_interval(seconds) == expected_tuple |
72 | | - |
73 | | - |
74 | 54 | def test_crons_task_success(): |
75 | 55 | fake_task = MagicMock() |
76 | 56 | fake_task.request = { |
@@ -339,6 +319,61 @@ def test_get_monitor_config_minutes(): |
339 | 319 | } |
340 | 320 |
|
341 | 321 |
|
| 322 | +@pytest.mark.parametrize( |
| 323 | + "run_every, value, unit", |
| 324 | + [ |
| 325 | + (datetime.timedelta(minutes=90), 90, "minute"), |
| 326 | + (datetime.timedelta(hours=2), 2, "hour"), |
| 327 | + (datetime.timedelta(hours=36), 36, "hour"), |
| 328 | + (datetime.timedelta(days=1), 1, "day"), |
| 329 | + ], |
| 330 | +) |
| 331 | +def test_get_monitor_config_interval_not_rounded(run_every, value, unit): |
| 332 | + app = MagicMock() |
| 333 | + app.timezone = "Europe/Vienna" |
| 334 | + |
| 335 | + celery_schedule = schedule(run_every=run_every) |
| 336 | + |
| 337 | + monitor_config = _get_monitor_config(celery_schedule, app, "foo") |
| 338 | + assert monitor_config["schedule"] == { |
| 339 | + "type": "interval", |
| 340 | + "value": value, |
| 341 | + "unit": unit, |
| 342 | + } |
| 343 | + |
| 344 | + |
| 345 | +def test_get_monitor_config_sub_minute_interval(): |
| 346 | + app = MagicMock() |
| 347 | + app.timezone = "Europe/Vienna" |
| 348 | + |
| 349 | + celery_schedule = schedule(run_every=datetime.timedelta(seconds=30)) |
| 350 | + |
| 351 | + with mock.patch("sentry_sdk.integrations.logger.warning") as mock_logger_warning: |
| 352 | + monitor_config = _get_monitor_config(celery_schedule, app, "foo") |
| 353 | + mock_logger_warning.assert_called_with( |
| 354 | + "Intervals shorter than one minute are not supported by Sentry Crons. Monitor '%s' has an interval of %s seconds. Use the `exclude_beat_tasks` option in the celery integration to exclude it.", |
| 355 | + "foo", |
| 356 | + 30, |
| 357 | + ) |
| 358 | + assert monitor_config == {} |
| 359 | + |
| 360 | + |
| 361 | +def test_get_monitor_config_interval_not_whole_minutes(): |
| 362 | + app = MagicMock() |
| 363 | + app.timezone = "Europe/Vienna" |
| 364 | + |
| 365 | + celery_schedule = schedule(run_every=datetime.timedelta(seconds=90)) |
| 366 | + |
| 367 | + with mock.patch("sentry_sdk.integrations.logger.warning") as mock_logger_warning: |
| 368 | + monitor_config = _get_monitor_config(celery_schedule, app, "foo") |
| 369 | + mock_logger_warning.assert_called_with( |
| 370 | + "Sentry Crons only supports intervals of whole minutes. Monitor '%s' has an interval of %s seconds. Use the `exclude_beat_tasks` option in the celery integration to exclude it.", |
| 371 | + "foo", |
| 372 | + 90, |
| 373 | + ) |
| 374 | + assert monitor_config == {} |
| 375 | + |
| 376 | + |
342 | 377 | def test_get_monitor_config_unknown(): |
343 | 378 | app = MagicMock() |
344 | 379 | app.timezone = "Europe/Vienna" |
|
0 commit comments