Skip to content

Commit

Permalink
parallelize the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Seppli11 committed Dec 13, 2024
1 parent d399514 commit 46c733b
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.Issue> issues = issues(PROJECT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand All @@ -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");
Expand All @@ -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);

Expand All @@ -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, "");
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,7 +32,7 @@
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";
Expand All @@ -42,7 +41,7 @@ class CustomRulesExampleTest {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,7 +32,7 @@
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";
Expand All @@ -42,7 +41,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.Issue> issues = issues(PROJECT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,15 +55,15 @@ class MetricsTest {
private static final Offset<Double> OFFSET = Offset.offset(0.01d);

@RegisterExtension
public static final OrchestratorExtension orchestrator = TestsUtils.ORCHESTRATOR;
public static final ConcurrentOrchestratorExtension orchestrator = TestsUtils.ORCHESTRATOR;

private static BuildResult buildResult;

@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/metrics"))
.setProjectKey(PROJECT_KEY)
.setProjectName(PROJECT_KEY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.Issue> issues = issues(PROJECT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.Issue> issues = issues(PROJECT).stream().sorted(Comparator.comparing(Issues.Issue::getRule))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 46c733b

Please sign in to comment.