Skip to content

Commit 90532f3

Browse files
ref(crons): Rename send_{message->checkin} (#54191)
1 parent cf6b14a commit 90532f3

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

tests/sentry/monitors/test_monitor_consumer.py

+46-46
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _create_monitor(self, **kwargs):
4646
**kwargs,
4747
)
4848

49-
def send_message(
49+
def send_checkin(
5050
self,
5151
monitor_slug: str,
5252
guid: Optional[str] = None,
@@ -89,7 +89,7 @@ def send_message(
8989
def test_payload(self) -> None:
9090
monitor = self._create_monitor(slug="my-monitor")
9191

92-
self.send_message(monitor.slug)
92+
self.send_checkin(monitor.slug)
9393

9494
checkin = MonitorCheckIn.objects.get(guid=self.guid)
9595
assert checkin.status == CheckInStatus.OK
@@ -108,15 +108,15 @@ def test_payload(self) -> None:
108108

109109
# Process another check-in to verify we set an expected time for the next check-in
110110
expected_time = monitor_environment.next_checkin
111-
self.send_message(monitor.slug)
111+
self.send_checkin(monitor.slug)
112112
checkin = MonitorCheckIn.objects.get(guid=self.guid)
113113
# the expected time should not include the margin of 5 minutes
114114
assert checkin.expected_time == expected_time - timedelta(minutes=5)
115115
assert checkin.trace_id.hex == self.trace_id
116116

117117
def test_passing(self) -> None:
118118
monitor = self._create_monitor(slug="my-monitor")
119-
self.send_message(monitor.slug)
119+
self.send_checkin(monitor.slug)
120120

121121
checkin = MonitorCheckIn.objects.get(guid=self.guid)
122122
assert checkin.status == CheckInStatus.OK
@@ -135,14 +135,14 @@ def test_passing(self) -> None:
135135

136136
# Process another check-in to verify we set an expected time for the next check-in
137137
expected_time = monitor_environment.next_checkin
138-
self.send_message(monitor.slug)
138+
self.send_checkin(monitor.slug)
139139
checkin = MonitorCheckIn.objects.get(guid=self.guid)
140140
# the expected time should not include the margin of 5 minutes
141141
assert checkin.expected_time == expected_time - timedelta(minutes=5)
142142

143143
def test_failing(self):
144144
monitor = self._create_monitor(slug="my-monitor")
145-
self.send_message(monitor.slug, status="error")
145+
self.send_checkin(monitor.slug, status="error")
146146

147147
checkin = MonitorCheckIn.objects.get(guid=self.guid)
148148
assert checkin.status == CheckInStatus.ERROR
@@ -160,7 +160,7 @@ def test_failing(self):
160160

161161
def test_disabled(self):
162162
monitor = self._create_monitor(status=ObjectStatus.DISABLED)
163-
self.send_message(monitor.slug, status="error")
163+
self.send_checkin(monitor.slug, status="error")
164164

165165
checkin = MonitorCheckIn.objects.get(guid=self.guid)
166166
assert checkin.status == CheckInStatus.ERROR
@@ -186,28 +186,28 @@ def test_create_lock(self):
186186
lock = locks.get(f"checkin-creation:{uuid.UUID(guid)}", duration=2, name="checkin_creation")
187187
lock.acquire()
188188

189-
self.send_message(monitor.slug, guid=guid)
189+
self.send_checkin(monitor.slug, guid=guid)
190190

191191
# Lock should prevent creation of new check-in
192192
assert len(MonitorCheckIn.objects.filter(monitor=monitor)) == 0
193193

194194
def test_check_in_timeout_at(self):
195195
monitor = self._create_monitor(slug="my-monitor")
196-
self.send_message(monitor.slug, status="in_progress")
196+
self.send_checkin(monitor.slug, status="in_progress")
197197

198198
checkin = MonitorCheckIn.objects.get(guid=self.guid)
199199
timeout_at = checkin.date_added.replace(second=0, microsecond=0) + timedelta(
200200
minutes=TIMEOUT
201201
)
202202
assert checkin.timeout_at == timeout_at
203203

204-
self.send_message(monitor.slug, guid=self.guid)
204+
self.send_checkin(monitor.slug, guid=self.guid)
205205
checkin = MonitorCheckIn.objects.get(guid=self.guid)
206206
assert checkin.status == CheckInStatus.OK
207207
assert checkin.timeout_at is None
208208

209209
new_guid = uuid.uuid4().hex
210-
self.send_message(
210+
self.send_checkin(
211211
"my-other-monitor",
212212
guid=new_guid,
213213
status="in_progress",
@@ -224,8 +224,8 @@ def test_check_in_timeout_at(self):
224224

225225
def test_check_in_update(self):
226226
monitor = self._create_monitor(slug="my-monitor")
227-
self.send_message(monitor.slug, status="in_progress")
228-
self.send_message(monitor.slug, guid=self.guid)
227+
self.send_checkin(monitor.slug, status="in_progress")
228+
self.send_checkin(monitor.slug, guid=self.guid)
229229

230230
checkin = MonitorCheckIn.objects.get(guid=self.guid)
231231
assert checkin.duration is not None
@@ -234,33 +234,33 @@ def test_check_in_existing_guid(self):
234234
monitor = self._create_monitor(slug="my-monitor")
235235
other_monitor = self._create_monitor(slug="other-monitor")
236236

237-
self.send_message(monitor.slug, status="in_progress")
238-
self.send_message(
237+
self.send_checkin(monitor.slug, status="in_progress")
238+
self.send_checkin(
239239
monitor.slug, guid=self.guid, status="done", enviroment="other-environment"
240240
)
241-
self.send_message(other_monitor.slug, guid=self.guid, status="done")
241+
self.send_checkin(other_monitor.slug, guid=self.guid, status="done")
242242

243243
# Assert check-in was not modified
244244
checkin = MonitorCheckIn.objects.get(guid=self.guid)
245245
assert checkin.status == CheckInStatus.IN_PROGRESS
246246

247247
def test_check_in_update_terminal(self):
248248
monitor = self._create_monitor(slug="my-monitor")
249-
self.send_message(monitor.slug, duration=10.0)
250-
self.send_message(monitor.slug, guid=self.guid, status="in_progress")
249+
self.send_checkin(monitor.slug, duration=10.0)
250+
self.send_checkin(monitor.slug, guid=self.guid, status="in_progress")
251251

252252
checkin = MonitorCheckIn.objects.get(guid=self.guid)
253253
assert checkin.duration == int(10.0 * 1000)
254254

255-
self.send_message(monitor.slug, duration=20.0, status="error")
256-
self.send_message(monitor.slug, guid=self.guid, status="in_progress")
255+
self.send_checkin(monitor.slug, duration=20.0, status="error")
256+
self.send_checkin(monitor.slug, guid=self.guid, status="in_progress")
257257

258258
checkin = MonitorCheckIn.objects.get(guid=self.guid)
259259
assert checkin.duration == int(20.0 * 1000)
260260

261261
def test_monitor_environment(self):
262262
monitor = self._create_monitor(slug="my-monitor")
263-
self.send_message(monitor.slug, environment="jungle")
263+
self.send_checkin(monitor.slug, environment="jungle")
264264

265265
checkin = MonitorCheckIn.objects.get(guid=self.guid)
266266
assert checkin.status == CheckInStatus.OK
@@ -278,7 +278,7 @@ def test_monitor_environment(self):
278278
)
279279

280280
def test_monitor_create(self):
281-
self.send_message(
281+
self.send_checkin(
282282
"my-new-monitor",
283283
monitor_config={"schedule": {"type": "crontab", "value": "13 * * * *"}},
284284
)
@@ -306,7 +306,7 @@ def test_monitor_create(self):
306306

307307
def test_monitor_update(self):
308308
monitor = self._create_monitor(slug="my-monitor")
309-
self.send_message(
309+
self.send_checkin(
310310
"my-monitor",
311311
monitor_config={"schedule": {"type": "crontab", "value": "13 * * * *"}},
312312
)
@@ -337,7 +337,7 @@ def test_monitor_update(self):
337337

338338
def test_check_in_empty_id(self):
339339
monitor = self._create_monitor(slug="my-monitor")
340-
self.send_message(
340+
self.send_checkin(
341341
"my-monitor",
342342
guid=str(uuid.UUID(int=0)),
343343
)
@@ -348,7 +348,7 @@ def test_check_in_empty_id(self):
348348

349349
def test_check_in_empty_id_update(self):
350350
monitor = self._create_monitor(slug="my-monitor")
351-
self.send_message(
351+
self.send_checkin(
352352
"my-monitor",
353353
status="in_progress",
354354
guid=str(uuid.UUID(int=0)),
@@ -361,9 +361,9 @@ def test_check_in_empty_id_update(self):
361361
# Send an event to a different monitor environment, tests that when we
362362
# use the empty UUID "latest" we properly scope to the latest of the
363363
# same monitor environment
364-
self.send_message("my-monitor", status="in_progress", environment="dev")
364+
self.send_checkin("my-monitor", status="in_progress", environment="dev")
365365

366-
self.send_message(
366+
self.send_checkin(
367367
"my-monitor",
368368
status="ok",
369369
guid=str(uuid.UUID(int=0)),
@@ -378,26 +378,26 @@ def test_rate_limit(self):
378378

379379
with mock.patch("sentry.monitors.consumers.monitor_consumer.CHECKIN_QUOTA_LIMIT", 1):
380380
# Try to ingest two the second will be rate limited
381-
self.send_message("my-monitor")
382-
self.send_message("my-monitor")
381+
self.send_checkin("my-monitor")
382+
self.send_checkin("my-monitor")
383383

384384
checkins = MonitorCheckIn.objects.filter(monitor_id=monitor.id)
385385
assert len(checkins) == 1
386386

387387
# Same monitor, diff environments
388-
self.send_message("my-monitor", environment="dev")
388+
self.send_checkin("my-monitor", environment="dev")
389389

390390
checkins = MonitorCheckIn.objects.filter(monitor_id=monitor.id)
391391
assert len(checkins) == 2
392392

393393
def test_invalid_guid_environment_match(self):
394394
monitor = self._create_monitor(slug="my-monitor")
395-
self.send_message(monitor.slug, status="in_progress")
395+
self.send_checkin(monitor.slug, status="in_progress")
396396

397397
checkin = MonitorCheckIn.objects.get(guid=self.guid)
398398
assert checkin.monitor_environment.environment.name == "production"
399399

400-
self.send_message(monitor.slug, guid=self.guid, status="ok", environment="test")
400+
self.send_checkin(monitor.slug, guid=self.guid, status="ok", environment="test")
401401

402402
checkin = MonitorCheckIn.objects.get(guid=self.guid)
403403
assert checkin.status == CheckInStatus.IN_PROGRESS
@@ -407,19 +407,19 @@ def test_invalid_duration(self):
407407
monitor = self._create_monitor(slug="my-monitor")
408408

409409
# Test invalid explicit durations
410-
self.send_message("my-monitor", status="in_progress")
410+
self.send_checkin("my-monitor", status="in_progress")
411411

412412
# Invalid check-in updates
413-
self.send_message("my-monitor", guid=self.guid, duration=-(1.0 / 1000))
414-
self.send_message(
413+
self.send_checkin("my-monitor", guid=self.guid, duration=-(1.0 / 1000))
414+
self.send_checkin(
415415
"my-monitor",
416416
guid=self.guid,
417417
duration=((BoundedPositiveIntegerField.MAX_VALUE + 1.0) / 1000),
418418
)
419419

420420
# Invalid check-in creations
421-
self.send_message("my-monitor", duration=-(1.0 / 1000))
422-
self.send_message(
421+
self.send_checkin("my-monitor", duration=-(1.0 / 1000))
422+
self.send_checkin(
423423
"my-monitor", duration=(BoundedPositiveIntegerField.MAX_VALUE + 1.0) / 1000
424424
)
425425

@@ -437,14 +437,14 @@ def test_invalid_duration(self):
437437
date_added=monitor.date_added - timedelta(weeks=52),
438438
)
439439

440-
self.send_message("my-monitor", guid=old_checkin.guid)
440+
self.send_checkin("my-monitor", guid=old_checkin.guid)
441441

442442
checkin = MonitorCheckIn.objects.get(guid=old_checkin.guid)
443443
assert checkin.status == CheckInStatus.IN_PROGRESS
444444
assert checkin.duration is None
445445

446446
def test_monitor_upsert(self):
447-
self.send_message(
447+
self.send_checkin(
448448
"my-monitor",
449449
monitor_config={"schedule": {"type": "crontab", "value": "13 * * * *"}},
450450
environment="my-environment",
@@ -462,7 +462,7 @@ def test_monitor_upsert(self):
462462
assert monitor_environment is not None
463463

464464
def test_monitor_upsert_invalid_slug(self):
465-
self.send_message(
465+
self.send_checkin(
466466
"some/slug@with-weird|stuff",
467467
monitor_config={"schedule": {"type": "crontab", "value": "0 * * * *"}},
468468
)
@@ -474,7 +474,7 @@ def test_monitor_upsert_invalid_slug(self):
474474
def test_monitor_upsert_temp_dual_read_invalid_slug(self):
475475
monitor = self._create_monitor(slug="my/monitor/invalid-slug")
476476

477-
self.send_message(
477+
self.send_checkin(
478478
"my/monitor/invalid-slug",
479479
monitor_config={"schedule": {"type": "crontab", "value": "0 * * * *"}},
480480
)
@@ -484,7 +484,7 @@ def test_monitor_upsert_temp_dual_read_invalid_slug(self):
484484
assert checkin.monitor_id == monitor.id
485485

486486
def test_monitor_invalid_config(self):
487-
self.send_message(
487+
self.send_checkin(
488488
"my-invalid-monitor",
489489
monitor_config={"schedule": {"type": "crontab", "value": "13 * * * * *"}},
490490
environment="my-environment",
@@ -495,7 +495,7 @@ def test_monitor_invalid_config(self):
495495
@override_settings(MAX_MONITORS_PER_ORG=2)
496496
def test_monitor_limits(self):
497497
for i in range(settings.MAX_MONITORS_PER_ORG + 2):
498-
self.send_message(
498+
self.send_checkin(
499499
f"my-monitor-{i}",
500500
monitor_config={"schedule": {"type": "crontab", "value": "13 * * * *"}},
501501
)
@@ -506,7 +506,7 @@ def test_monitor_limits(self):
506506
@override_settings(MAX_ENVIRONMENTS_PER_MONITOR=2)
507507
def test_monitor_environment_limits(self):
508508
for i in range(settings.MAX_ENVIRONMENTS_PER_MONITOR + 2):
509-
self.send_message(
509+
self.send_checkin(
510510
"my-monitor",
511511
monitor_config={"schedule": {"type": "crontab", "value": "13 * * * *"}},
512512
environment=f"my-environment-{i}",
@@ -521,7 +521,7 @@ def test_monitor_environment_limits(self):
521521
def test_monitor_environment_validation(self):
522522
invalid_name = "x" * 65
523523

524-
self.send_message(
524+
self.send_checkin(
525525
"my-monitor",
526526
monitor_config={"schedule": {"type": "crontab", "value": "13 * * * *"}},
527527
environment=f"my-environment-{invalid_name}",
@@ -541,7 +541,7 @@ def test_organization_killswitch(self):
541541
)
542542
options.set("crons.organization.disable-check-in", opt_val)
543543

544-
self.send_message(monitor.slug)
544+
self.send_checkin(monitor.slug)
545545

546546
opt_val = killswitches.validate_user_input("crons.organization.disable-check-in", [])
547547
options.set("crons.organization.disable-check-in", opt_val)

0 commit comments

Comments
 (0)