|
| 1 | +from datetime import datetime |
| 2 | +from unittest import mock |
| 3 | + |
| 4 | +from arroyo.backends.kafka import KafkaPayload |
| 5 | +from arroyo.processing.strategies import ProcessingStrategy |
| 6 | +from arroyo.types import BrokerValue, Message, Partition, Topic |
| 7 | +from django.utils import timezone |
| 8 | +from sentry_kafka_schemas.schema_types.monitors_incident_occurrences_v1 import IncidentOccurrence |
| 9 | + |
| 10 | +from sentry.monitors.consumers.incident_occurrences_consumer import ( |
| 11 | + MONITORS_INCIDENT_OCCURRENCES, |
| 12 | + MonitorIncidentOccurenceStrategyFactory, |
| 13 | +) |
| 14 | + |
| 15 | +partition = Partition(Topic("test"), 0) |
| 16 | + |
| 17 | + |
| 18 | +def create_consumer() -> ProcessingStrategy[KafkaPayload]: |
| 19 | + factory = MonitorIncidentOccurenceStrategyFactory() |
| 20 | + commit = mock.Mock() |
| 21 | + return factory.create_with_partitions(commit, {partition: 0}) |
| 22 | + |
| 23 | + |
| 24 | +def sned_incident_occurrence( |
| 25 | + consumer: ProcessingStrategy[KafkaPayload], |
| 26 | + ts: datetime, |
| 27 | + incident_occurrence: IncidentOccurrence, |
| 28 | +): |
| 29 | + value = BrokerValue( |
| 30 | + KafkaPayload(b"fake-key", MONITORS_INCIDENT_OCCURRENCES.encode(incident_occurrence), []), |
| 31 | + partition, |
| 32 | + 1, |
| 33 | + ts, |
| 34 | + ) |
| 35 | + consumer.submit(Message(value)) |
| 36 | + |
| 37 | + |
| 38 | +def test_simple(): |
| 39 | + # XXX(epurkhiser): Doesn't really test anything yet |
| 40 | + ts = timezone.now().replace(second=0, microsecond=0) |
| 41 | + |
| 42 | + consumer = create_consumer() |
| 43 | + sned_incident_occurrence( |
| 44 | + consumer, |
| 45 | + ts, |
| 46 | + { |
| 47 | + "clock_tick_ts": 1617895645, |
| 48 | + "received_ts": 1617895650, |
| 49 | + "failed_checkin_id": 123456, |
| 50 | + "incident_id": 987654, |
| 51 | + "previous_checkin_ids": [111222, 333444, 55666], |
| 52 | + }, |
| 53 | + ) |
0 commit comments