aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-12-03 15:19:06 +0100
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-12-04 11:01:08 +0100
commit41959b471deb06e239e11f9fd5774db913182216 (patch)
tree1281112cd524bbd90a279879df9706baa2809ac8
parente5f5ca562f10727eead9e0de8fe1a090dea8399d (diff)
downloadsonarqube-41959b471deb06e239e11f9fd5774db913182216.tar.gz
sonarqube-41959b471deb06e239e11f9fd5774db913182216.zip
SONAR-6925 cancelled tasks must not be the last task for a component
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/ws/ComponentActionTest.java21
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml1
2 files changed, 22 insertions, 0 deletions
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/ws/ComponentActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/ws/ComponentActionTest.java
index dc3d62589c6..15c2dffa707 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/ws/ComponentActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/ws/ComponentActionTest.java
@@ -99,6 +99,27 @@ public class ComponentActionTest {
assertThat(response.getCurrent().getId()).isEqualTo("T3");
}
+ @Test
+ public void canceled_tasks_must_not_be_picked_as_current_analysis() {
+ userSession.addComponentUuidPermission(UserRole.USER, "PROJECT_1", "PROJECT_1");
+ insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
+ insertActivity("T2", "PROJECT_2", CeActivityDto.Status.FAILED);
+ insertActivity("T3", "PROJECT_1", CeActivityDto.Status.SUCCESS);
+ insertActivity("T4", "PROJECT_1", CeActivityDto.Status.CANCELED);
+ insertActivity("T5", "PROJECT_1", CeActivityDto.Status.CANCELED);
+
+ TestResponse wsResponse = tester.newRequest()
+ .setParam("componentId", "PROJECT_1")
+ .setMediaType(MediaTypes.PROTOBUF)
+ .execute();
+
+ WsCe.ProjectResponse response = Protobuf.read(wsResponse.getInputStream(), WsCe.ProjectResponse.PARSER);
+ assertThat(response.getQueueCount()).isEqualTo(0);
+ // T3 is the latest task executed on PROJECT_1 ignoring Canceled ones
+ assertThat(response.hasCurrent()).isTrue();
+ assertThat(response.getCurrent().getId()).isEqualTo("T3");
+ }
+
private CeQueueDto insertQueue(String taskUuid, String componentUuid, CeQueueDto.Status status) {
CeQueueDto queueDto = new CeQueueDto();
queueDto.setTaskType(CeTaskTypes.REPORT);
diff --git a/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml b/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
index 25d79d14080..155d1da39e2 100644
--- a/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
+++ b/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
@@ -38,6 +38,7 @@
select uuid
from ce_activity
where is_last_key=#{isLastKey}
+ and status &lt;&gt; 'CANCELED'
order by id desc
</select>