]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-15225 Cancelled tasks for indexations should be count as failures
authorJacek <jacek.poreda@sonarsource.com>
Tue, 14 Sep 2021 13:05:42 +0000 (15:05 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 16 Sep 2021 20:03:30 +0000 (20:03 +0000)
server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java
server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndexSyncProgressChecker.java
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 0c9b277b638eb3c73cb25d8a9aea8bc72029bf4a..613f000eb6d74a486508b6c6f9005adc0a448de6 100644 (file)
@@ -88,8 +88,8 @@ public class CeActivityDao implements Dao {
     return Optional.ofNullable(mapper(dbSession).selectLastByComponentUuidAndTaskType(componentUuid, taskType));
   }
 
-  public boolean hasAnyFailedIssueSyncTask(DbSession dbSession) {
-    return mapper(dbSession).hasAnyFailedIssueSyncTask() > 0;
+  public boolean hasAnyFailedOrCancelledIssueSyncTask(DbSession dbSession) {
+    return mapper(dbSession).hasAnyFailedOrCancelledIssueSyncTask() > 0;
   }
 
   private static CeActivityMapper mapper(DbSession dbSession) {
index a52771f9a51405f0120f965160a46d8acb8b0f9c..b6a2a00c1cbfdbc37e6ecfde03d4d233b18333e6 100644 (file)
@@ -47,7 +47,7 @@ public interface CeActivityMapper {
   @CheckForNull
   CeActivityDto selectLastByComponentUuidAndTaskType(@Param("componentUuid") String componentUuid, @Param("taskType") String taskType);
 
-  short hasAnyFailedIssueSyncTask();
+  short hasAnyFailedOrCancelledIssueSyncTask();
 
   List<CeActivityDto> selectByTaskType(@Param("taskType") String taskType);
 }
index cc24d1b5dab2c3aff11375f9d684c97d5e91c336..17c222152dd7d2f5eab4a72971898f9094205a38 100644 (file)
     and ca.is_last = ${_true}
   </select>
 
-  <sql id="hasAnyFailedIssueSyncTaskSql">
+  <sql id="hasAnyFailedOrCancelledIssueSyncTaskSql">
     select
     case when exists
     (
     select ca.uuid from ce_activity ca inner join project_branches pb on ca.component_uuid = pb.uuid
     where ca.task_type = 'ISSUE_SYNC'
-    and ca.status = 'FAILED'
+    and ca.status in ('FAILED', 'CANCELED')
     and pb.need_issue_sync = ${_true}
     )
     then 1
     end
   </sql>
 
-  <select id="hasAnyFailedIssueSyncTask" parameterType="map" resultType="short" >
-    <include refid="hasAnyFailedIssueSyncTaskSql"/>
+  <select id="hasAnyFailedOrCancelledIssueSyncTask" parameterType="map" resultType="short" >
+    <include refid="hasAnyFailedOrCancelledIssueSyncTaskSql"/>
   </select>
 
-  <select id="hasAnyFailedIssueSyncTask" parameterType="map" resultType="short" databaseId="oracle">
-    <include refid="hasAnyFailedIssueSyncTaskSql"/>
+  <select id="hasAnyFailedOrCancelledIssueSyncTask" parameterType="map" resultType="short" databaseId="oracle">
+    <include refid="hasAnyFailedOrCancelledIssueSyncTaskSql"/>
     from dual
   </select>
 
index af602397115a3691f75956cd2ebd2cac21dffc39..870eacaea7bfdc9eca3782fe81cec88af6d68914 100644 (file)
@@ -762,8 +762,8 @@ public class CeActivityDaoTest {
   }
 
   @Test
-  public void hasAnyFailedIssueSyncTask() {
-    assertThat(underTest.hasAnyFailedIssueSyncTask(db.getSession())).isFalse();
+  public void hasAnyFailedOrCancelledIssueSyncTask() {
+    assertThat(underTest.hasAnyFailedOrCancelledIssueSyncTask(db.getSession())).isFalse();
 
     insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
     insert("TASK_2", REPORT, MAINCOMPONENT_1, FAILED);
@@ -779,31 +779,40 @@ public class CeActivityDaoTest {
     });
     insert("TASK_4", CeTaskTypes.BRANCH_ISSUE_SYNC, projectDto2.getUuid(), projectDto2.getUuid(), SUCCESS);
 
-    assertThat(underTest.hasAnyFailedIssueSyncTask(db.getSession())).isFalse();
+    assertThat(underTest.hasAnyFailedOrCancelledIssueSyncTask(db.getSession())).isFalse();
 
     ProjectDto projectDto3 = db.components().insertPrivateProjectDto(branchDto -> branchDto.setNeedIssueSync(false), c -> {
     }, p -> {
     });
     insert("TASK_5", CeTaskTypes.BRANCH_ISSUE_SYNC, projectDto3.getUuid(), projectDto3.getUuid(), SUCCESS);
 
-    BranchDto projectBranch = db.components()
+    BranchDto projectBranch1 = db.components()
       .insertProjectBranch(projectDto3, branchDto -> branchDto.setNeedIssueSync(true));
 
-    insert("TASK_6", CeTaskTypes.BRANCH_ISSUE_SYNC, projectBranch.getUuid(), projectDto3.getUuid(), FAILED);
+    insert("TASK_6", CeTaskTypes.BRANCH_ISSUE_SYNC, projectBranch1.getUuid(), projectDto3.getUuid(), FAILED);
+
+    BranchDto projectBranch2 = db.components()
+        .insertProjectBranch(projectDto3, branchDto -> branchDto.setNeedIssueSync(true));
+
+    insert("TASK_7", CeTaskTypes.BRANCH_ISSUE_SYNC, projectBranch2.getUuid(), projectDto3.getUuid(), CANCELED);
 
     // failed task and project branch still exists and need sync
-    assertThat(underTest.hasAnyFailedIssueSyncTask(db.getSession())).isTrue();
+    assertThat(underTest.hasAnyFailedOrCancelledIssueSyncTask(db.getSession())).isTrue();
+
+    // assume branch has been re-analysed
+    db.getDbClient().branchDao().updateNeedIssueSync(db.getSession(), projectBranch1.getUuid(), false);
 
     // assume branch has been re-analysed
-    db.getDbClient().branchDao().updateNeedIssueSync(db.getSession(), projectBranch.getUuid(), false);
+    db.getDbClient().branchDao().updateNeedIssueSync(db.getSession(), projectBranch2.getUuid(), false);
 
-    assertThat(underTest.hasAnyFailedIssueSyncTask(db.getSession())).isFalse();
+    assertThat(underTest.hasAnyFailedOrCancelledIssueSyncTask(db.getSession())).isFalse();
 
     // assume branch has been deleted
-    db.getDbClient().purgeDao().deleteBranch(db.getSession(), projectBranch.getUuid());
+    db.getDbClient().purgeDao().deleteBranch(db.getSession(), projectBranch1.getUuid());
+    db.getDbClient().purgeDao().deleteBranch(db.getSession(), projectBranch2.getUuid());
 
     // associated branch does not exist, so there is no failures - either it has been deleted or purged or reanalysed
-    assertThat(underTest.hasAnyFailedIssueSyncTask(db.getSession())).isFalse();
+    assertThat(underTest.hasAnyFailedOrCancelledIssueSyncTask(db.getSession())).isFalse();
   }
 
   private CeActivityDto insert(String uuid, String type, @Nullable String mainComponentUuid, CeActivityDto.Status status) {
index 9633d2c4e754e150b1a49b757bc384dab5c645a5..4b233836b553769323e1fb71c8031ee832f61555 100644 (file)
@@ -42,7 +42,7 @@ public class IssueIndexSyncProgressChecker {
 
   public IssueSyncProgress getIssueSyncProgress(DbSession dbSession) {
     int completed = dbClient.branchDao().countByNeedIssueSync(dbSession, false);
-    boolean hasFailures = dbClient.ceActivityDao().hasAnyFailedIssueSyncTask(dbSession);
+    boolean hasFailures = dbClient.ceActivityDao().hasAnyFailedOrCancelledIssueSyncTask(dbSession);
     boolean isCompleted = !dbClient.ceQueueDao().hasAnyIssueSyncTaskPendingOrInProgress(dbSession);
     int total = dbClient.branchDao().countAll(dbSession);
     return new IssueSyncProgress(isCompleted, completed, total, hasFailures);
index 2af634fa6ae806115567150ba4cb6939593172ee..6dbc9287cc6850859be17c15b2ee80613243ae65 100644 (file)
@@ -4119,7 +4119,7 @@ indexation.progression_with_error={0}% complete with some {link}.
 indexation.progression_with_error.link=tasks failing
 indexation.completed=All project data has been reloaded.
 indexation.completed_with_error=SonarQube completed the reload of project data. Some {link} causing some projects to remain unavailable.
-indexation.completed_with_error.link=tasks failed
+indexation.completed_with_error.link=tasks failed or cancelled
 indexation.admin_link=See {link} for more information.
 indexation.page_unavailable.title.issues=Issues page is temporarily unavailable
 indexation.page_unavailable.title.portfolios=Portfolios page is temporarily unavailable