@@ -1293,3 +1293,123 @@ def test_bundle_analysis_processor_task_no_upload(
12931293 assert commit .state == "complete"
12941294 assert upload .state == "processed"
12951295 assert upload .upload_type == "carriedforward"
1296+
1297+
1298+ @pytest .mark .django_db (databases = {"default" , "timeseries" })
1299+ def test_bundle_analysis_processor_task_carryforward (
1300+ mocker ,
1301+ dbsession ,
1302+ mock_storage ,
1303+ ):
1304+ storage_path = (
1305+ "v1/repos/testing/ed1bdd67-8fd2-4cdb-ac9e-39b99e4a3892/bundle_report.sqlite"
1306+ )
1307+ mock_storage .write_file (get_bucket_name (), storage_path , "test-content" )
1308+
1309+ mocker .patch .object (
1310+ BundleAnalysisProcessorTask ,
1311+ "app" ,
1312+ tasks = {
1313+ bundle_analysis_save_measurements_task_name : mocker .MagicMock (),
1314+ },
1315+ )
1316+
1317+ commit = CommitFactory .create (state = "pending" )
1318+ dbsession .add (commit )
1319+ dbsession .flush ()
1320+
1321+ commit_report = CommitReport (
1322+ commit_id = commit .id_ , report_type = ReportType .BUNDLE_ANALYSIS .value
1323+ )
1324+ dbsession .add (commit_report )
1325+ dbsession .flush ()
1326+
1327+ upload = UploadFactory .create (
1328+ storage_path = storage_path , report = commit_report , state = "processed"
1329+ )
1330+ dbsession .add (upload )
1331+ dbsession .flush ()
1332+
1333+ BundleAnalysisProcessorTask ().run_impl (
1334+ dbsession ,
1335+ {"results" : [{"previous" : "result" }]},
1336+ repoid = commit .repoid ,
1337+ commitid = commit .commitid ,
1338+ commit_yaml = {},
1339+ params = {
1340+ "upload_id" : None ,
1341+ "commit" : commit .commitid ,
1342+ },
1343+ )
1344+
1345+ # A new upload wasn't created because the caching was skipped
1346+ total_uploads = (
1347+ dbsession .query (Upload ).filter_by (report_id = commit_report .id ).count ()
1348+ )
1349+ assert total_uploads == 1
1350+
1351+ # A new report wasn't created either
1352+ total_ba_reports = (
1353+ dbsession .query (CommitReport ).filter_by (commit_id = commit .id ).count ()
1354+ )
1355+ assert total_ba_reports == 1
1356+
1357+
1358+ @pytest .mark .django_db (databases = {"default" , "timeseries" })
1359+ def test_bundle_analysis_processor_task_carryforward_error (
1360+ mocker ,
1361+ dbsession ,
1362+ mock_storage ,
1363+ ):
1364+ storage_path = (
1365+ "v1/repos/testing/ed1bdd67-8fd2-4cdb-ac9e-39b99e4a3892/bundle_report.sqlite"
1366+ )
1367+ mock_storage .write_file (get_bucket_name (), storage_path , "test-content" )
1368+
1369+ mocker .patch .object (
1370+ BundleAnalysisProcessorTask ,
1371+ "app" ,
1372+ tasks = {
1373+ bundle_analysis_save_measurements_task_name : mocker .MagicMock (),
1374+ },
1375+ )
1376+
1377+ commit = CommitFactory .create (state = "pending" )
1378+ dbsession .add (commit )
1379+ dbsession .flush ()
1380+
1381+ commit_report = CommitReport (
1382+ commit_id = commit .id_ , report_type = ReportType .BUNDLE_ANALYSIS .value
1383+ )
1384+ dbsession .add (commit_report )
1385+ dbsession .flush ()
1386+
1387+ upload = UploadFactory .create (
1388+ storage_path = storage_path , report = commit_report , state = "error"
1389+ )
1390+ dbsession .add (upload )
1391+ dbsession .flush ()
1392+
1393+ BundleAnalysisProcessorTask ().run_impl (
1394+ dbsession ,
1395+ {"results" : [{"previous" : "result" }]},
1396+ repoid = commit .repoid ,
1397+ commitid = commit .commitid ,
1398+ commit_yaml = {},
1399+ params = {
1400+ "upload_id" : None ,
1401+ "commit" : commit .commitid ,
1402+ },
1403+ )
1404+
1405+ # A new upload was created because all the previous uploads were in error states
1406+ total_uploads = (
1407+ dbsession .query (Upload ).filter_by (report_id = commit_report .id ).count ()
1408+ )
1409+ assert total_uploads == 2
1410+
1411+ # There should still only be 1 BA report
1412+ total_ba_reports = (
1413+ dbsession .query (CommitReport ).filter_by (commit_id = commit .id ).count ()
1414+ )
1415+ assert total_ba_reports == 1
0 commit comments