From e917bf90386024b84a477fc17b141c3cdba58bf9 Mon Sep 17 00:00:00 2001 From: Sebastian Zumbrunn Date: Mon, 16 Dec 2024 16:01:30 +0100 Subject: [PATCH] SONARPY-2462: Parallelize the qa_plugin tests (#2248) --- its/plugin/it-python-plugin-test/pom.xml | 2 +- .../python/it/plugin/BanditReportTest.java | 6 +- .../com/sonar/python/it/plugin/CPDTest.java | 5 +- .../ConcurrentOrchestratorExtension.java | 78 +++++++++++++++++++ .../sonar/python/it/plugin/CoverageTest.java | 11 ++- .../it/plugin/CustomRulesExampleTest.java | 11 +-- .../python/it/plugin/CustomRulesTest.java | 7 +- .../python/it/plugin/Flake8ReportTest.java | 6 +- .../sonar/python/it/plugin/MetricsTest.java | 5 +- .../python/it/plugin/MypyReportTest.java | 6 +- .../sonar/python/it/plugin/NoSonarTest.java | 5 +- .../python/it/plugin/NotebookPluginTest.java | 9 ++- .../python/it/plugin/PylintReportTest.java | 6 +- .../python/it/plugin/RuffReportTest.java | 6 +- .../python/it/plugin/TestReportTest.java | 5 +- .../sonar/python/it/plugin/TestRulesTest.java | 5 +- .../com/sonar/python/it/plugin/TestSuite.java | 40 ---------- .../sonar/python/it/plugin/TestsUtils.java | 3 +- .../test/resources/junit-platform.properties | 4 + 19 files changed, 124 insertions(+), 96 deletions(-) create mode 100644 its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/ConcurrentOrchestratorExtension.java delete mode 100644 its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/TestSuite.java create mode 100644 its/plugin/it-python-plugin-test/src/test/resources/junit-platform.properties diff --git a/its/plugin/it-python-plugin-test/pom.xml b/its/plugin/it-python-plugin-test/pom.xml index af2b10fee0..2ba2fecc38 100644 --- a/its/plugin/it-python-plugin-test/pom.xml +++ b/its/plugin/it-python-plugin-test/pom.xml @@ -63,7 +63,7 @@ maven-surefire-plugin - com/sonar/python/it/plugin/TestSuite.java + com/sonar/python/it/plugin/*.java diff --git a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/BanditReportTest.java b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/BanditReportTest.java index 58650f370f..94708c7dbb 100644 --- a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/BanditReportTest.java +++ b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/BanditReportTest.java @@ -16,8 +16,6 @@ */ package com.sonar.python.it.plugin; -import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.io.File; import java.util.List; import org.junit.jupiter.api.Test; @@ -33,14 +31,14 @@ class BanditReportTest { private static final String PROJECT = "bandit_project"; @RegisterExtension - public static final OrchestratorExtension ORCHESTRATOR = TestsUtils.ORCHESTRATOR; + public static final ConcurrentOrchestratorExtension ORCHESTRATOR = TestsUtils.ORCHESTRATOR; @Test void import_report() { ORCHESTRATOR.getServer().provisionProject(PROJECT, PROJECT); ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT, "py", "no_rule"); ORCHESTRATOR.executeBuild( - SonarScanner.create() + ORCHESTRATOR.createSonarScanner() .setProjectDir(new File("projects/bandit_project"))); List issues = issues(PROJECT); diff --git a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/CPDTest.java b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/CPDTest.java index f80295cb15..4370305dee 100644 --- a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/CPDTest.java +++ b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/CPDTest.java @@ -17,7 +17,6 @@ package com.sonar.python.it.plugin; import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.io.File; import org.assertj.core.data.Offset; import org.junit.jupiter.api.BeforeAll; @@ -41,13 +40,13 @@ class CPDTest { private static final String DUPLICATED_LINES_DENSITY = "duplicated_lines_density"; @RegisterExtension - public static final OrchestratorExtension ORCHESTRATOR = TestsUtils.ORCHESTRATOR; + public static final ConcurrentOrchestratorExtension ORCHESTRATOR = TestsUtils.ORCHESTRATOR; @BeforeAll static void startServer() { ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY); ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT_KEY, "py", "no_rule"); - SonarScanner build = SonarScanner.create() + SonarScanner build = ORCHESTRATOR.createSonarScanner() .setProjectDir(new File("projects/cpd")) .setProjectKey(PROJECT_KEY) .setProjectName(PROJECT_KEY) diff --git a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/ConcurrentOrchestratorExtension.java b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/ConcurrentOrchestratorExtension.java new file mode 100644 index 0000000000..ec69f4cd94 --- /dev/null +++ b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/ConcurrentOrchestratorExtension.java @@ -0,0 +1,78 @@ +/* + * SonarQube Python Plugin + * Copyright (C) 2012-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package com.sonar.python.it.plugin; + +import com.sonar.orchestrator.Orchestrator; +import com.sonar.orchestrator.OrchestratorBuilder; +import com.sonar.orchestrator.build.SonarScanner; +import com.sonar.orchestrator.build.SonarScannerInstaller; +import com.sonar.orchestrator.config.Configuration; +import com.sonar.orchestrator.container.SonarDistribution; +import com.sonar.orchestrator.server.StartupLogWatcher; +import com.sonar.orchestrator.util.System2; +import com.sonar.orchestrator.version.Version; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicInteger; +import org.jetbrains.annotations.Nullable; +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.ExtensionContext; + +public class ConcurrentOrchestratorExtension extends Orchestrator implements BeforeAllCallback { + private static final AtomicInteger REQUESTED_ORCHESTRATORS_KEY = new AtomicInteger(); + private static final CountDownLatch IS_ORCHESTRATOR_READY = new CountDownLatch(1); + + ConcurrentOrchestratorExtension(Configuration config, SonarDistribution distribution, @Nullable StartupLogWatcher startupLogWatcher) { + super(config, distribution, startupLogWatcher); + } + + @Override + public void beforeAll(ExtensionContext context) throws InterruptedException { + if (REQUESTED_ORCHESTRATORS_KEY.getAndIncrement() == 0) { + start(); + + new SonarScannerInstaller(getConfiguration().locators()).install(Version.create(SonarScanner.DEFAULT_SCANNER_VERSION), getConfiguration().fileSystem().workspace()); + IS_ORCHESTRATOR_READY.countDown(); + + } else { + IS_ORCHESTRATOR_READY.await(); + } + } + + + public SonarScanner createSonarScanner() { + return SonarScanner.create(); + } + + public static ConcurrentOrchestratorExtensionBuilder builderEnv() { + return new ConcurrentOrchestratorExtensionBuilder(Configuration.createEnv()); + } + + public static class ConcurrentOrchestratorExtensionBuilder extends OrchestratorBuilder { + ConcurrentOrchestratorExtensionBuilder(Configuration initialConfig) { + this(initialConfig, System2.INSTANCE); + } + + ConcurrentOrchestratorExtensionBuilder(Configuration initialConfig, System2 system2) { + super(initialConfig, system2); + } + + @Override + protected ConcurrentOrchestratorExtension build(Configuration finalConfig, SonarDistribution distribution, StartupLogWatcher startupLogWatcher) { + return new ConcurrentOrchestratorExtension(finalConfig, distribution, startupLogWatcher); + } + } +} diff --git a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/CoverageTest.java b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/CoverageTest.java index 2420de9798..82d543d8de 100644 --- a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/CoverageTest.java +++ b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/CoverageTest.java @@ -20,7 +20,6 @@ import com.google.common.collect.ImmutableMap.Builder; import com.sonar.orchestrator.build.BuildResult; import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.io.File; import java.util.HashMap; import java.util.Map; @@ -33,7 +32,7 @@ class CoverageTest { private static final String COVERAGE_PROJECT = "projects/coverage_project"; @RegisterExtension - public static final OrchestratorExtension ORCHESTRATOR = TestsUtils.ORCHESTRATOR; + public static final ConcurrentOrchestratorExtension ORCHESTRATOR = TestsUtils.ORCHESTRATOR; private static final String PROJECT_KEY = "coverage_project"; private static final String LINES_TO_COVER = "lines_to_cover"; @@ -55,7 +54,7 @@ void basic_coverage_reports_with_windows_paths() { } private static void basicCoverageReports(String utReportPath) { - SonarScanner build = SonarScanner.create() + SonarScanner build = ORCHESTRATOR.createSonarScanner() .setProjectDir(new File(COVERAGE_PROJECT)) .setProperty(DEPRECATED_COVERAGE_REPORT_PATH, "someReport") .setProperty(COVERAGE_REPORT_PATHS, utReportPath+",it-coverage1.xml,it-coverage2.xml"); @@ -75,7 +74,7 @@ private static void basicCoverageReports(String utReportPath) { @Test void default_values() { - SonarScanner build = SonarScanner.create() + SonarScanner build = ORCHESTRATOR.createSonarScanner() .setProjectDir(new File(COVERAGE_PROJECT)); ORCHESTRATOR.executeBuild(build); @@ -90,7 +89,7 @@ void default_values() { @Test void empty_property() { - SonarScanner build = SonarScanner.create() + SonarScanner build = ORCHESTRATOR.createSonarScanner() .setProjectDir(new File(COVERAGE_PROJECT)) .setProperty(DEPRECATED_COVERAGE_REPORT_PATH, "") .setProperty(COVERAGE_REPORT_PATHS, ""); @@ -106,7 +105,7 @@ void empty_property() { @Test void empty_coverage_report() { - SonarScanner build = SonarScanner.create() + SonarScanner build = ORCHESTRATOR.createSonarScanner() .setProjectDir(new File(COVERAGE_PROJECT)) .setProperty(DEPRECATED_COVERAGE_REPORT_PATH, EMPTY_XML) .setProperty(COVERAGE_REPORT_PATHS, EMPTY_XML); diff --git a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/CustomRulesExampleTest.java b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/CustomRulesExampleTest.java index 87f6307437..6cfc5ff585 100644 --- a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/CustomRulesExampleTest.java +++ b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/CustomRulesExampleTest.java @@ -17,12 +17,12 @@ package com.sonar.python.it.plugin; import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.io.File; import java.util.List; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.api.parallel.ResourceLock; import org.sonarqube.ws.Issues; import org.sonarqube.ws.client.issues.SearchRequest; @@ -30,19 +30,20 @@ import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; +@ResourceLock("project/custom_rules") class CustomRulesExampleTest { @RegisterExtension - public static final OrchestratorExtension orchestrator = TestsUtils.ORCHESTRATOR; + public static final ConcurrentOrchestratorExtension orchestrator = TestsUtils.ORCHESTRATOR; - private static final String PROJECT_KEY = "custom-rules"; - private static final String PROJECT_NAME = "Custom Rules"; + private static final String PROJECT_KEY = "custom-rules-example"; + private static final String PROJECT_NAME = "Custom Rules Example"; @BeforeAll static void prepare() { orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_NAME); orchestrator.getServer().associateProjectToQualityProfile(PROJECT_KEY, "py", "python-custom-rules-example-profile"); - SonarScanner build = SonarScanner.create() + SonarScanner build = orchestrator.createSonarScanner() .setProjectDir(new File("projects/custom_rules")) .setProjectKey(PROJECT_KEY) .setProjectName(PROJECT_NAME) diff --git a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/CustomRulesTest.java b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/CustomRulesTest.java index 16797d5ca6..66a1657ca7 100644 --- a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/CustomRulesTest.java +++ b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/CustomRulesTest.java @@ -17,12 +17,12 @@ package com.sonar.python.it.plugin; import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.io.File; import java.util.List; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.api.parallel.ResourceLock; import org.sonarqube.ws.Issues; import org.sonarqube.ws.client.issues.SearchRequest; @@ -30,10 +30,11 @@ import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; +@ResourceLock("project/custom_rules") class CustomRulesTest { @RegisterExtension - public static final OrchestratorExtension orchestrator = TestsUtils.ORCHESTRATOR; + public static final ConcurrentOrchestratorExtension orchestrator = TestsUtils.ORCHESTRATOR; private static final String PROJECT_KEY = "custom-rules"; private static final String PROJECT_NAME = "Custom Rules"; @@ -42,7 +43,7 @@ class CustomRulesTest { static void prepare() { orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_NAME); orchestrator.getServer().associateProjectToQualityProfile(PROJECT_KEY, "py", "python-custom-rules-profile"); - SonarScanner build = SonarScanner.create() + SonarScanner build = orchestrator.createSonarScanner() .setProjectDir(new File("projects/custom_rules")) .setProjectKey(PROJECT_KEY) .setProjectName(PROJECT_NAME) diff --git a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/Flake8ReportTest.java b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/Flake8ReportTest.java index fc275e9da9..5046236595 100644 --- a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/Flake8ReportTest.java +++ b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/Flake8ReportTest.java @@ -16,8 +16,6 @@ */ package com.sonar.python.it.plugin; -import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.io.File; import java.util.List; import org.junit.jupiter.api.Test; @@ -33,14 +31,14 @@ class Flake8ReportTest { private static final String PROJECT = "flake8_project"; @RegisterExtension - public static final OrchestratorExtension ORCHESTRATOR = TestsUtils.ORCHESTRATOR; + public static final ConcurrentOrchestratorExtension ORCHESTRATOR = TestsUtils.ORCHESTRATOR; @Test void import_report() { ORCHESTRATOR.getServer().provisionProject(PROJECT, PROJECT); ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT, "py", "no_rule"); ORCHESTRATOR.executeBuild( - SonarScanner.create() + ORCHESTRATOR.createSonarScanner() .setProjectDir(new File("projects/flake8_project"))); List issues = issues(PROJECT); diff --git a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/MetricsTest.java b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/MetricsTest.java index 70fa027352..4f516afedd 100644 --- a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/MetricsTest.java +++ b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/MetricsTest.java @@ -18,7 +18,6 @@ import com.sonar.orchestrator.build.BuildResult; import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.io.File; import org.assertj.core.data.Offset; import org.junit.jupiter.api.BeforeAll; @@ -56,7 +55,7 @@ class MetricsTest { private static final Offset OFFSET = Offset.offset(0.01d); @RegisterExtension - public static final OrchestratorExtension orchestrator = TestsUtils.ORCHESTRATOR; + public static final ConcurrentOrchestratorExtension orchestrator = TestsUtils.ORCHESTRATOR; private static BuildResult buildResult; @@ -64,7 +63,7 @@ class MetricsTest { static void startServer() { orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY); orchestrator.getServer().associateProjectToQualityProfile(PROJECT_KEY, "py", "no_rule"); - SonarScanner build = SonarScanner.create() + SonarScanner build = orchestrator.createSonarScanner() .setProjectDir(new File("projects/metrics")) .setProjectKey(PROJECT_KEY) .setProjectName(PROJECT_KEY) diff --git a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/MypyReportTest.java b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/MypyReportTest.java index 89a17acc68..9440151b98 100644 --- a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/MypyReportTest.java +++ b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/MypyReportTest.java @@ -16,8 +16,6 @@ */ package com.sonar.python.it.plugin; -import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.io.File; import java.util.List; import org.junit.jupiter.api.Test; @@ -33,14 +31,14 @@ class MypyReportTest { private static final String PROJECT = "mypy_project"; @RegisterExtension - public static final OrchestratorExtension ORCHESTRATOR = TestsUtils.ORCHESTRATOR; + public static final ConcurrentOrchestratorExtension ORCHESTRATOR = TestsUtils.ORCHESTRATOR; @Test void import_report() { ORCHESTRATOR.getServer().provisionProject(PROJECT, PROJECT); ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT, "py", "no_rule"); ORCHESTRATOR.executeBuild( - SonarScanner.create() + ORCHESTRATOR.createSonarScanner() .setProjectDir(new File("projects/mypy_project"))); List issues = issues(PROJECT); diff --git a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/NoSonarTest.java b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/NoSonarTest.java index 700e6f1c29..952854c7b9 100644 --- a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/NoSonarTest.java +++ b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/NoSonarTest.java @@ -17,7 +17,6 @@ package com.sonar.python.it.plugin; import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.io.File; import java.util.List; import org.junit.jupiter.api.BeforeAll; @@ -34,13 +33,13 @@ class NoSonarTest { private static final String PROFILE_NAME = "nosonar"; @RegisterExtension - public static final OrchestratorExtension ORCHESTRATOR = TestsUtils.ORCHESTRATOR; + public static final ConcurrentOrchestratorExtension ORCHESTRATOR = TestsUtils.ORCHESTRATOR; @BeforeAll static void startServer() { ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY); ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT_KEY, "py", PROFILE_NAME); - SonarScanner build = SonarScanner.create() + SonarScanner build = ORCHESTRATOR.createSonarScanner() .setProjectDir(new File("projects", PROJECT_KEY)) .setProjectKey(PROJECT_KEY) .setProjectName(PROJECT_KEY) diff --git a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/NotebookPluginTest.java b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/NotebookPluginTest.java index a0c9d11e3c..b81c304088 100644 --- a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/NotebookPluginTest.java +++ b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/NotebookPluginTest.java @@ -17,7 +17,6 @@ package com.sonar.python.it.plugin; import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.io.File; import java.util.List; import org.junit.jupiter.api.BeforeAll; @@ -33,12 +32,12 @@ class NotebookPluginTest { private static final String PROJECT_KEY = "ipynb_json_project"; @RegisterExtension - public static final OrchestratorExtension ORCHESTRATOR = TestsUtils.ORCHESTRATOR; + public static final ConcurrentOrchestratorExtension ORCHESTRATOR = TestsUtils.ORCHESTRATOR; @BeforeAll static void startServer() { ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY); - SonarScanner build = SonarScanner.create() + SonarScanner build = ORCHESTRATOR.createSonarScanner() .setProjectDir(new File("projects", PROJECT_KEY)) .setProjectKey(PROJECT_KEY) .setProjectName(PROJECT_KEY) @@ -50,7 +49,9 @@ static void startServer() { @Test void test() { List issues = issues(PROJECT_KEY); - assertThat(issues).isEmpty(); + assertThat(issues) + .extracting(Issues.Issue::getRule) + .containsExactlyInAnyOrder("ipython:PrintStatementUsage", "ipython:S1854", "ipython:S3457", "ipython:S5727", "ipython:S5727"); } } diff --git a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/PylintReportTest.java b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/PylintReportTest.java index 0bcc2556a4..fa3fd96acc 100644 --- a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/PylintReportTest.java +++ b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/PylintReportTest.java @@ -17,8 +17,6 @@ package com.sonar.python.it.plugin; import com.sonar.orchestrator.build.BuildResult; -import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.io.File; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -32,7 +30,7 @@ class PylintReportTest { private static final String LEGACY_PROPERTY = "sonar.python.pylint.reportPath"; @RegisterExtension - public static final OrchestratorExtension ORCHESTRATOR = TestsUtils.ORCHESTRATOR; + public static final ConcurrentOrchestratorExtension ORCHESTRATOR = TestsUtils.ORCHESTRATOR; @Test void import_report() { @@ -82,7 +80,7 @@ private static BuildResult analyseProjectWithReport(String projectKey, String pr ORCHESTRATOR.getServer().associateProjectToQualityProfile(projectKey, "py", "no_rule"); return ORCHESTRATOR.executeBuild( - SonarScanner.create() + ORCHESTRATOR.createSonarScanner() .setDebugLogs(true) .setProjectKey(projectKey) .setProjectName(projectKey) diff --git a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/RuffReportTest.java b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/RuffReportTest.java index 7d7cd8b618..f05d64c022 100644 --- a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/RuffReportTest.java +++ b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/RuffReportTest.java @@ -16,8 +16,6 @@ */ package com.sonar.python.it.plugin; -import com.sonar.orchestrator.Orchestrator; -import com.sonar.orchestrator.build.SonarScanner; import java.io.File; import java.util.Comparator; import java.util.List; @@ -34,14 +32,14 @@ class RuffReportTest { private final String PROJECT = "ruff_project"; @RegisterExtension - public static final Orchestrator ORCHESTRATOR = TestsUtils.ORCHESTRATOR; + public static final ConcurrentOrchestratorExtension ORCHESTRATOR = TestsUtils.ORCHESTRATOR; @Test void import_report() { ORCHESTRATOR.getServer().provisionProject(PROJECT, PROJECT); ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT, "py", "no_rule"); ORCHESTRATOR.executeBuild( - SonarScanner.create() + ORCHESTRATOR.createSonarScanner() .setProjectDir(new File("projects/ruff_project"))); List issues = issues(PROJECT).stream().sorted(Comparator.comparing(Issues.Issue::getRule)) diff --git a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/TestReportTest.java b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/TestReportTest.java index d433c1f542..d985ba8df3 100644 --- a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/TestReportTest.java +++ b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/TestReportTest.java @@ -21,7 +21,6 @@ import com.google.common.collect.Maps; import com.sonar.orchestrator.build.BuildResult; import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.io.File; import java.util.HashMap; import java.util.Map; @@ -42,10 +41,10 @@ class TestReportTest { public static final String TEST_EXECUTION_TIME = "test_execution_time"; @RegisterExtension - public static final OrchestratorExtension ORCHESTRATOR = TestsUtils.ORCHESTRATOR; + public static final ConcurrentOrchestratorExtension ORCHESTRATOR = TestsUtils.ORCHESTRATOR; private static SonarScanner createBuild(String projectKey, String testReportPath) { - return SonarScanner.create() + return ORCHESTRATOR.createSonarScanner() .setProjectKey(projectKey) .setProjectName(projectKey) .setProjectDir(new File("projects/nosetests_project")) diff --git a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/TestRulesTest.java b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/TestRulesTest.java index b66097207b..9af7d02ed3 100644 --- a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/TestRulesTest.java +++ b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/TestRulesTest.java @@ -17,7 +17,6 @@ package com.sonar.python.it.plugin; import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.io.File; import java.util.List; import org.junit.jupiter.api.BeforeAll; @@ -33,7 +32,7 @@ class TestRulesTest { @RegisterExtension - public static final OrchestratorExtension orchestrator = TestsUtils.ORCHESTRATOR; + public static final ConcurrentOrchestratorExtension orchestrator = TestsUtils.ORCHESTRATOR; private static final String PROJECT_KEY = "test-rules"; private static final String PROJECT_NAME = "Test Rules"; @@ -43,7 +42,7 @@ class TestRulesTest { static void prepare() { orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_NAME); orchestrator.getServer().associateProjectToQualityProfile(PROJECT_KEY, "py", "python-test-rules-profile"); - BUILD = SonarScanner.create() + BUILD = orchestrator.createSonarScanner() .setProjectDir(new File("projects/test_code")) .setProjectKey(PROJECT_KEY) .setProjectName(PROJECT_NAME) diff --git a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/TestSuite.java b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/TestSuite.java deleted file mode 100644 index 91111e88f0..0000000000 --- a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/TestSuite.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * SonarQube Python Plugin - * Copyright (C) 2012-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Sonar Source-Available License for more details. - * - * You should have received a copy of the Sonar Source-Available License - * along with this program; if not, see https://sonarsource.com/license/ssal/ - */ -package com.sonar.python.it.plugin; - -import org.junit.platform.suite.api.SelectClasses; -import org.junit.platform.suite.api.Suite; - -@Suite -@SelectClasses({ - BanditReportTest.class, - CoverageTest.class, - CPDTest.class, - CustomRulesTest.class, - Flake8ReportTest.class, - SonarLintIPythonTest.class, - MetricsTest.class, - MypyReportTest.class, - NoSonarTest.class, - PylintReportTest.class, - RuffReportTest.class, - TestReportTest.class, - TestRulesTest.class, - SonarLintTest.class -}) -public class TestSuite { -} diff --git a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/TestsUtils.java b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/TestsUtils.java index 4396f8fa18..8d78fccbfe 100644 --- a/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/TestsUtils.java +++ b/its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/TestsUtils.java @@ -16,7 +16,6 @@ */ package com.sonar.python.it.plugin; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import com.sonar.orchestrator.locator.FileLocation; import java.io.File; import java.util.ArrayList; @@ -46,7 +45,7 @@ public final class TestsUtils { public static final FileLocation PLUGIN_LOCATION = FileLocation.byWildcardMavenFilename(new File("../../../sonar-python-plugin/target"), "sonar-python-plugin-*.jar"); - public static final OrchestratorExtension ORCHESTRATOR = OrchestratorExtension.builderEnv() + public static final ConcurrentOrchestratorExtension ORCHESTRATOR = ConcurrentOrchestratorExtension.builderEnv() .useDefaultAdminCredentialsForBuilds(true) .setSonarVersion(System.getProperty(SQ_VERSION_PROPERTY, DEFAULT_SQ_VERSION)) .addPlugin(PLUGIN_LOCATION) diff --git a/its/plugin/it-python-plugin-test/src/test/resources/junit-platform.properties b/its/plugin/it-python-plugin-test/src/test/resources/junit-platform.properties new file mode 100644 index 0000000000..45a60bfe59 --- /dev/null +++ b/its/plugin/it-python-plugin-test/src/test/resources/junit-platform.properties @@ -0,0 +1,4 @@ +junit.jupiter.execution.parallel.enabled = true +junit.jupiter.execution.parallel.mode.classes.default = concurrent +junit.jupiter.execution.parallel.config.strategy=dynamic +junit.jupiter.execution.parallel.config.dynamic.factor=0.5