|
@@ -10,7 +10,7 @@ from arroyo.backends.kafka import KafkaPayload
|
|
|
from sentry.models import File
|
|
|
from sentry.replays.consumers.recording.factory import ProcessReplayRecordingStrategyFactory
|
|
|
from sentry.replays.models import ReplayRecordingSegment
|
|
|
-from sentry.testutils.cases import TestCase
|
|
|
+from sentry.testutils import TestCase
|
|
|
|
|
|
|
|
|
class TestRecordingsConsumerEndToEnd(TestCase):
|
|
@@ -70,3 +70,61 @@ class TestRecordingsConsumerEndToEnd(TestCase):
|
|
|
assert recording
|
|
|
assert recording.checksum == sha1(b"testfoobar").hexdigest()
|
|
|
assert ReplayRecordingSegment.objects.get(replay_id=self.replay_id)
|
|
|
+
|
|
|
+ def test_duplicate_segment_flow(self):
|
|
|
+ processing_strategy = self.processing_factory().create_with_partitions(lambda x: None, None)
|
|
|
+ segment_id = 0
|
|
|
+ consumer_messages = [
|
|
|
+ {
|
|
|
+ "payload": f'{{"segment_id":{segment_id}}}\ntest'.encode(),
|
|
|
+ "replay_id": self.replay_id,
|
|
|
+ "project_id": self.project.id,
|
|
|
+ "id": self.replay_recording_id,
|
|
|
+ "chunk_index": 0,
|
|
|
+ "type": "replay_recording_chunk",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "type": "replay_recording",
|
|
|
+ "replay_id": self.replay_id,
|
|
|
+ "replay_recording": {
|
|
|
+ "chunks": 1,
|
|
|
+ "id": self.replay_recording_id,
|
|
|
+ },
|
|
|
+ "project_id": self.project.id,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "payload": f'{{"segment_id":{segment_id}}}\nduplicatedyadada'.encode(),
|
|
|
+ "replay_id": self.replay_id,
|
|
|
+ "project_id": self.project.id,
|
|
|
+ "id": self.replay_recording_id,
|
|
|
+ "chunk_index": 0,
|
|
|
+ "type": "replay_recording_chunk",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "type": "replay_recording",
|
|
|
+ "replay_id": self.replay_id,
|
|
|
+ "replay_recording": {
|
|
|
+ "chunks": 1,
|
|
|
+ "id": self.replay_recording_id,
|
|
|
+ },
|
|
|
+ "project_id": self.project.id,
|
|
|
+ },
|
|
|
+ ]
|
|
|
+ for message in consumer_messages:
|
|
|
+ processing_strategy.submit(
|
|
|
+ Message(
|
|
|
+ Partition(Topic("ingest-replay-recordings"), 1),
|
|
|
+ 1,
|
|
|
+ KafkaPayload(b"key", msgpack.packb(message), [("should_drop", b"1")]),
|
|
|
+ datetime.now(),
|
|
|
+ )
|
|
|
+ )
|
|
|
+ processing_strategy.poll()
|
|
|
+ processing_strategy.join(1)
|
|
|
+ processing_strategy.terminate()
|
|
|
+ recording_file_name = f"rr:{self.replay_id}:{segment_id}"
|
|
|
+
|
|
|
+ assert len(File.objects.filter(name=recording_file_name)) == 2
|
|
|
+ # right now both files should be inserted, but only one segment is created,
|
|
|
+ # so the second one is "lost".
|
|
|
+ assert ReplayRecordingSegment.objects.get(replay_id=self.replay_id)
|