|
16 | 16 | from helpers.exceptions import RepositoryWithoutValidBotError |
17 | 17 | from helpers.log_context import LogContext, set_log_context |
18 | 18 | from services.lock_manager import LockRetry |
19 | | -from services.processing.intermediate import intermediate_report_key |
20 | 19 | from services.processing.merging import get_joined_flag, update_uploads |
21 | 20 | from services.processing.types import MergeResult, ProcessingResult |
22 | 21 | from services.timeseries import MeasurementName |
@@ -1259,105 +1258,18 @@ def test_idempotency_check_proceeds_when_uploads_not_finished( |
1259 | 1258 | # Verify that _process_reports_with_lock WAS called |
1260 | 1259 | mock_process.assert_called_once() |
1261 | 1260 |
|
1262 | | - @pytest.mark.django_db |
1263 | | - def test_reconstruct_processing_results_falls_back_to_database_when_redis_expires( |
1264 | | - self, |
1265 | | - dbsession, |
1266 | | - mocker, |
1267 | | - mock_storage, |
1268 | | - mock_repo_provider, |
1269 | | - mock_redis, |
1270 | | - mock_self_app, |
1271 | | - ): |
1272 | | - """Test that finisher falls back to database when Redis ProcessingState expires. |
1273 | | -
|
1274 | | - This tests the edge case where Redis keys expire after 24h TTL, but uploads |
1275 | | - were processed and have intermediate reports. The finisher should find them |
1276 | | - via database query and include them in the final report. |
1277 | | - """ |
1278 | | - commit = CommitFactory.create() |
1279 | | - dbsession.add(commit) |
1280 | | - dbsession.flush() |
1281 | | - |
1282 | | - report = CommitReport(commit_id=commit.id_) |
1283 | | - dbsession.add(report) |
1284 | | - dbsession.flush() |
1285 | | - |
1286 | | - # Create uploads in "started" state (simulating Redis state expired) |
1287 | | - upload_1 = UploadFactory.create( |
1288 | | - report=report, state="started", state_id=UploadState.UPLOADED.db_id |
1289 | | - ) |
1290 | | - upload_2 = UploadFactory.create( |
1291 | | - report=report, state="started", state_id=UploadState.UPLOADED.db_id |
1292 | | - ) |
1293 | | - dbsession.add(upload_1) |
1294 | | - dbsession.add(upload_2) |
1295 | | - dbsession.flush() |
1296 | | - |
1297 | | - # Mock Redis to simulate intermediate reports exist (confirms uploads were processed) |
1298 | | - mock_redis.exists.side_effect = lambda key: ( |
1299 | | - key == intermediate_report_key(upload_1.id) |
1300 | | - or key == intermediate_report_key(upload_2.id) |
1301 | | - ) |
1302 | | - |
1303 | | - # Mock ProcessingState to return empty (simulating Redis expiration) |
1304 | | - mock_state = mocker.MagicMock() |
1305 | | - mock_state.get_uploads_for_merging.return_value = set() # Redis expired |
1306 | | - mock_state.get_upload_numbers.return_value = mocker.MagicMock( |
1307 | | - processing=0, processed=0 |
1308 | | - ) |
1309 | | - mocker.patch("tasks.upload_finisher.ProcessingState", return_value=mock_state) |
1310 | | - |
1311 | | - # Mock the processing methods |
1312 | | - mocker.patch("tasks.upload_finisher.load_intermediate_reports", return_value=[]) |
1313 | | - mocker.patch("tasks.upload_finisher.update_uploads") |
1314 | | - mock_process = mocker.patch.object( |
1315 | | - UploadFinisherTask, "_process_reports_with_lock" |
1316 | | - ) |
1317 | | - |
1318 | | - # Call run_impl without processing_results to trigger reconstruction |
1319 | | - task = UploadFinisherTask() |
1320 | | - task.run_impl( |
1321 | | - dbsession, |
1322 | | - processing_results=None, # Triggers reconstruction |
1323 | | - repoid=commit.repoid, |
1324 | | - commitid=commit.commitid, |
1325 | | - commit_yaml={}, |
1326 | | - ) |
1327 | | - |
1328 | | - # Verify that _find_started_uploads_with_reports was called (via reconstruction) |
1329 | | - # This is verified by checking that _process_reports_with_lock was called |
1330 | | - # with processing_results containing our uploads |
1331 | | - mock_process.assert_called_once() |
1332 | | - call_args = mock_process.call_args |
1333 | | - # processing_results is the 4th positional argument (index 0 is args tuple) |
1334 | | - processing_results = call_args[0][3] |
1335 | | - |
1336 | | - # Verify both uploads are included in processing_results |
1337 | | - upload_ids_in_results = {r["upload_id"] for r in processing_results} |
1338 | | - assert upload_1.id in upload_ids_in_results |
1339 | | - assert upload_2.id in upload_ids_in_results |
1340 | | - assert len(processing_results) == 2 |
1341 | | - |
1342 | | - # Verify both are marked as successful (have intermediate reports) |
1343 | | - assert all(r["successful"] for r in processing_results) |
1344 | | - |
1345 | 1261 | @pytest.mark.django_db |
1346 | 1262 | def test_reconstruct_processing_results_returns_empty_when_no_uploads_found( |
1347 | 1263 | self, dbsession, mocker, mock_redis, mock_self_app |
1348 | 1264 | ): |
1349 | | - """Test that finisher returns empty list when no uploads found in Redis or DB. |
1350 | | -
|
1351 | | - This tests the edge case where Redis expires AND no uploads exist in database |
1352 | | - in "started" state with intermediate reports. |
1353 | | - """ |
| 1265 | + """Test that finisher returns empty list when no uploads are merge-ready.""" |
1354 | 1266 | commit = CommitFactory.create() |
1355 | 1267 | dbsession.add(commit) |
1356 | 1268 | dbsession.flush() |
1357 | 1269 |
|
1358 | | - # Mock ProcessingState to return empty (simulating Redis expiration) |
| 1270 | + # Mock ProcessingState to return empty merge-ready set. |
1359 | 1271 | mock_state = mocker.MagicMock() |
1360 | | - mock_state.get_uploads_for_merging.return_value = set() # Redis expired |
| 1272 | + mock_state.get_uploads_for_merging.return_value = set() |
1361 | 1273 | mocker.patch("tasks.upload_finisher.ProcessingState", return_value=mock_state) |
1362 | 1274 |
|
1363 | 1275 | # Call run_impl without processing_results to trigger reconstruction |
|
0 commit comments