|
2 | 2 | from unittest import mock |
3 | 3 | from uuid import uuid1 |
4 | 4 |
|
| 5 | +import pytest |
5 | 6 | from django.db.utils import IntegrityError |
6 | 7 | from django.utils import timezone |
7 | 8 |
|
|
18 | 19 | from sentry.models.debugfile import ProguardArtifactRelease, ProjectDebugFile |
19 | 20 | from sentry.models.organization import Organization |
20 | 21 | from sentry.models.project import Project |
| 22 | +from sentry.objectstore import get_debug_files_session |
21 | 23 | from sentry.testutils.cases import TestCase |
| 24 | +from sentry.testutils.skips import requires_objectstore |
22 | 25 |
|
23 | 26 |
|
24 | 27 | class SyncArtifactBundlesTest(TestCase): |
@@ -243,6 +246,55 @@ def test_sync_project_debug_files(self) -> None: |
243 | 246 | assert target_project_debug_file.code_id == source_project_debug_file.code_id |
244 | 247 | assert target_project_debug_file.cpu_name == source_project_debug_file.cpu_name |
245 | 248 |
|
| 249 | + @requires_objectstore |
| 250 | + def test_sync_objectstore_project_debug_files(self) -> None: |
| 251 | + content = b"objectstore-backed-debug-file" |
| 252 | + content_type = "application/x-mach-binary" |
| 253 | + date_created = timezone.now() |
| 254 | + source_storage_path = get_debug_files_session( |
| 255 | + self.source_org.id, self.source_proj_foo.id |
| 256 | + ).put(content, compression="none", content_type=content_type) |
| 257 | + source_project_debug_file = ProjectDebugFile.objects.create( |
| 258 | + project_id=self.source_proj_foo.id, |
| 259 | + file=None, |
| 260 | + storage_path=source_storage_path, |
| 261 | + content_type=content_type, |
| 262 | + file_size=len(content), |
| 263 | + date_created=date_created, |
| 264 | + checksum="a" * 40, |
| 265 | + object_name="test.dSYM", |
| 266 | + cpu_name="x86_64", |
| 267 | + debug_id="67e9247c-814e-392b-a027-dbde6748fcbf", |
| 268 | + code_id="code-id", |
| 269 | + data={"features": ["debug"]}, |
| 270 | + ) |
| 271 | + |
| 272 | + _sync_project_debug_files( |
| 273 | + source_org=self.source_org, |
| 274 | + target_org=self.target_org, |
| 275 | + cutoff_date=self.last_three_days(), |
| 276 | + ) |
| 277 | + |
| 278 | + target_project_debug_file = ProjectDebugFile.objects.get( |
| 279 | + project_id=self.target_proj_foo.id, |
| 280 | + debug_id=source_project_debug_file.debug_id, |
| 281 | + ) |
| 282 | + |
| 283 | + assert target_project_debug_file.file_id is None |
| 284 | + assert target_project_debug_file.storage_path is not None |
| 285 | + assert target_project_debug_file.storage_path != source_project_debug_file.storage_path |
| 286 | + assert target_project_debug_file.content_type == content_type |
| 287 | + assert target_project_debug_file.file_size == len(content) |
| 288 | + assert target_project_debug_file.date_created == date_created |
| 289 | + assert target_project_debug_file.getfile().read() == content |
| 290 | + |
| 291 | + target_project_debug_file.delete() |
| 292 | + source_project_debug_file.refresh_from_db() |
| 293 | + assert source_project_debug_file.getfile().read() == content |
| 294 | + |
| 295 | + with pytest.raises(ProjectDebugFile.DoesNotExist): |
| 296 | + target_project_debug_file.refresh_from_db() |
| 297 | + |
246 | 298 | def test_sync_project_debug_files_with_old_uploads(self) -> None: |
247 | 299 | source_project_debug_file = self.create_dif_file( |
248 | 300 | self.source_proj_foo, |
|
0 commit comments