diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2018-04-19 15:14:31 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-05-10 20:20:54 +0200 |
commit | 56844138c6d4b5a0a0365c08fd44d94135395154 (patch) | |
tree | 0791942cf173cf8efef8c29f28804c6a5dddb0b5 /tests/src | |
parent | efdcb66474cb9fea9d77501e8dad428cd81cdd1e (diff) | |
download | sonarqube-56844138c6d4b5a0a0365c08fd44d94135395154.tar.gz sonarqube-56844138c6d4b5a0a0365c08fd44d94135395154.zip |
SONAR-10593 SONAR-10315 support plugin uninstall before CE processing
Diffstat (limited to 'tests/src')
-rw-r--r-- | tests/src/test/java/org/sonarqube/tests/serverSystem/BlueGreenTest.java | 93 |
1 files changed, 65 insertions, 28 deletions
diff --git a/tests/src/test/java/org/sonarqube/tests/serverSystem/BlueGreenTest.java b/tests/src/test/java/org/sonarqube/tests/serverSystem/BlueGreenTest.java index 106a47a1e82..cc81e8e6074 100644 --- a/tests/src/test/java/org/sonarqube/tests/serverSystem/BlueGreenTest.java +++ b/tests/src/test/java/org/sonarqube/tests/serverSystem/BlueGreenTest.java @@ -23,7 +23,6 @@ import com.google.common.util.concurrent.Uninterruptibles; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.SonarScanner; import java.io.File; -import java.io.IOException; import java.util.concurrent.TimeUnit; import org.apache.commons.io.FileUtils; import org.junit.After; @@ -34,11 +33,12 @@ import org.junit.rules.TemporaryFolder; import org.junit.rules.TestRule; import org.junit.rules.Timeout; import org.sonarqube.qa.util.Tester; -import org.sonarqube.qa.util.pageobjects.Navigation; import org.sonarqube.ws.Ce; import org.sonarqube.ws.Projects; import org.sonarqube.ws.client.ce.ActivityStatusRequest; +import org.sonarqube.ws.client.plugins.UninstallRequest; import org.sonarqube.ws.client.qualityprofiles.AddProjectRequest; +import util.ItUtils; import util.XooProjectBuilder; import static org.assertj.core.api.Assertions.assertThat; @@ -68,7 +68,7 @@ public class BlueGreenTest { } @Test - public void test_change_of_version_at_runtime() throws Exception { + public void upgrade_analyzer_when_analysis_is_pending_in_compute_engine_queue() throws Exception { orchestrator = newOrchestratorBuilder() .addPlugin(pluginArtifact("blue-green-plugin-v1")) .addPlugin(xooPlugin()) @@ -77,44 +77,50 @@ public class BlueGreenTest { orchestrator.start(); tester.before(); - // pause compute engine so that analysis is kept pending - tester.wsClient().ce().pause(); - Projects.CreateWsResponse.Project project = tester.projects().provision(); - associateProjectToProfile(project, "Blue Profile"); - analyze(project); - assertThat(loadCeActivity().getPending()).isEqualTo(1); + Project project = new Project(); + project.associateToXooProfile("Blue Profile"); + project.analyzeAndWait(); + // assert 2 issues + security rating E (rule A is blocker, rule B is critical) + assertThat(ItUtils.getMeasureAsDouble(orchestrator, project.getKey(), "violations")).isEqualTo(2.0); + assertThat(ItUtils.getMeasureAsDouble(orchestrator, project.getKey(), "security_rating")).isEqualTo(5.0); + assertThat(ItUtils.getMeasureAsDouble(orchestrator, project.getKey(), "blue")).isEqualTo(10.0); + assertThat(ItUtils.getMeasureAsDouble(orchestrator, project.getKey(), "bluegreen")).isEqualTo(20.0); - // open browser - Navigation browser = tester.openBrowser(); + // remove rule "A" and metric "blue" between analysis and execution of Compute Engine + // 1. pause compute engine so that the second analysis is kept pending + tester.wsClient().ce().pause(); + project.analyze(); + assertThat(loadCeActivity().getPending()).isEqualTo(1); - // upgrade plugin + // 2. upgrade plugin and verify that analysis is still pending in CE queue File pluginV2 = pluginArtifact("blue-green-plugin-v2").getFile(); FileUtils.copyFileToDirectory(pluginV2, new File(orchestrator.getServer().getHome(), "extensions/downloads")); orchestrator.restartServer(); - - // analysis task is still pending Ce.ActivityStatusWsResponse ceActivity = loadCeActivity(); assertThat(ceActivity.getInProgress()).isEqualTo(0); assertThat(ceActivity.getPending()).isEqualTo(1); + // 3. resume the queue and verify that the issue on rule A is ignored. Only + // the critical issue on rule B is remaining resumeAndWaitForCeQueueEmpty(); + assertThat(ItUtils.getMeasureAsDouble(orchestrator, project.getKey(), "violations")).isEqualTo(1.0); + assertThat(ItUtils.getMeasureAsDouble(orchestrator, project.getKey(), "security_rating")).isEqualTo(4.0); + assertThat(ItUtils.getMeasure(orchestrator, project.getKey(), "blue")).isNull(); + assertThat(ItUtils.getMeasureAsDouble(orchestrator, project.getKey(), "bluegreen")).isEqualTo(20.0); - // TODO check issues and measures - } - - private void analyze(Projects.CreateWsResponse.Project project) throws IOException { - File projectDir = new XooProjectBuilder(project.getKey()) - .setFilesPerModule(1) - .build(temp.newFolder()); - orchestrator.executeBuild(SonarScanner.create(projectDir), false); - } + // test removal of analyzer. Analysis should not fail when queue is resumed. + tester.wsClient().ce().pause(); + project.analyze(); + tester.wsClient().plugins().uninstall(new UninstallRequest().setKey("xoo")); + tester.wsClient().plugins().uninstall(new UninstallRequest().setKey("bluegreen")); + orchestrator.restartServer(); - private void associateProjectToProfile(Projects.CreateWsResponse.Project project, String xooProfileName) { - tester.wsClient().qualityprofiles().addProject(new AddProjectRequest() - .setProject(project.getKey()) - .setLanguage("xoo") - .setQualityProfile(xooProfileName)); + resumeAndWaitForCeQueueEmpty(); + assertThat(ItUtils.getMeasureAsDouble(orchestrator, project.getKey(), "violations")).isEqualTo(0.0); + assertThat(ItUtils.getMeasureAsDouble(orchestrator, project.getKey(), "security_rating")).isEqualTo(1.0); + assertThat(ItUtils.getMeasure(orchestrator, project.getKey(), "blue")).isNull(); + assertThat(ItUtils.getMeasure(orchestrator, project.getKey(), "bluegreen")).isNull(); } private void resumeAndWaitForCeQueueEmpty() { @@ -131,4 +137,35 @@ public class BlueGreenTest { private Ce.ActivityStatusWsResponse loadCeActivity() { return tester.wsClient().ce().activityStatus(new ActivityStatusRequest()); } + + private class Project { + private final Projects.CreateWsResponse.Project project; + private final File dir; + + Project() throws Exception { + this.project = tester.projects().provision(); + this.dir = new XooProjectBuilder(project.getKey()) + .setFilesPerModule(1) + .build(temp.newFolder()); + } + + String getKey() { + return project.getKey(); + } + + void associateToXooProfile(String name) { + tester.wsClient().qualityprofiles().addProject(new AddProjectRequest() + .setProject(project.getKey()) + .setLanguage("xoo") + .setQualityProfile(name)); + } + + void analyzeAndWait() { + orchestrator.executeBuild(SonarScanner.create(dir), true); + } + + void analyze() { + orchestrator.executeBuild(SonarScanner.create(dir), false); + } + } } |