Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SONARPY-2475 split ruling into two #2256

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,30 @@
- source cirrus-env QA
- source set_maven_build_version $BUILD_NUMBER
- cd its/ruling
- mvn verify -Dsonar.runtimeVersion=LATEST_RELEASE -Dmaven.test.redirectTestOutputToFile=false -B -e -V -Dtest=PythonRulingTest -Djunit.jupiter.execution.parallel.config.dynamic.factor=1
- mvn verify -Dsonar.runtimeVersion=LATEST_RELEASE -Dmaven.test.redirectTestOutputToFile=false -B -e -V -Dtest=PythonRulingTest -Djunit.jupiter.execution.parallel.config.dynamic.factor=1 -DexcludedGroups=big-it-project
cleanup_before_cache_script: cleanup_maven_repository

ruling_big_task:
depends_on:
- build
<<: *ONLY_SONARSOURCE_QA
eks_container:
<<: *QA_CONTAINER_DEFINITION
cpu: 5
memory: 16G
env:
CIRRUS_CLONE_DEPTH: 10
SONARSOURCE_QA: true
maven_cache:
folder: ${CIRRUS_WORKING_DIR}/.m2/repository
<<: *ORCHESTRATOR_CACHE_DEFINITION
submodules_script:
- git submodule update --init
ruling_script:
- source cirrus-env QA
- source set_maven_build_version $BUILD_NUMBER
- cd its/ruling
- mvn verify -Dsonar.runtimeVersion=LATEST_RELEASE -Dmaven.test.redirectTestOutputToFile=false -B -e -V -Dtest=PythonRulingTest -Djunit.jupiter.execution.parallel.config.dynamic.factor=1 -Dgroups=big-it-project
cleanup_before_cache_script: cleanup_maven_repository

pr_analysis_qa_task:
Expand All @@ -226,10 +249,11 @@
- mvn verify -Dsonar.runtimeVersion=LATEST_RELEASE -Dmaven.test.redirectTestOutputToFile=false -B -e -V -Dtest=PythonPrAnalysisTest
cleanup_before_cache_script: cleanup_maven_repository

promote_task:

Check warning on line 252 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L252

task "promote" depends on task "ws_scan", but their only_if conditions are different

Check warning on line 252 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L252

task "promote" depends on task "ws_scan", but their only_if conditions are different
depends_on:
- test_analyze
- ruling
- ruling_big
- plugin_qa
- ws_scan
- pr_analysis_qa
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import java.nio.file.Files;
import java.util.Collections;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
Expand All @@ -38,9 +40,9 @@
import static org.sonar.python.it.RulingHelper.getOrchestrator;

@Execution(ExecutionMode.CONCURRENT)
@ExtendWith(TestDurationMeasureExtension.class)
class PythonRulingTest {


@RegisterExtension
public static final OrchestratorExtension ORCHESTRATOR = getOrchestrator();
public static final Configuration CONFIGURATION = ORCHESTRATOR.getConfiguration();
Expand All @@ -65,6 +67,7 @@ static void install_sonar_scanner() {
}

@Test
@Tag("big-it-project")
void test_airflow() throws IOException {
SonarScanner build = buildWithCommonProperties("airflow");
build.setProperty("sonar.sources", "airflow");
Expand Down Expand Up @@ -167,6 +170,7 @@ void test_docker_compose() throws IOException {
}

@Test
@Tag("big-it-project")
void test_indico() throws IOException {
SonarScanner build = buildWithCommonProperties("indico");
build.setProperty("sonar.sources", "indico");
Expand Down Expand Up @@ -222,13 +226,15 @@ void test_pecos() throws IOException {
}

@Test
@Tag("big-it-project")
void test_saleor() throws IOException {
SonarScanner build = buildWithCommonProperties("saleor");
build.setProperty("sonar.sources", "saleor");
executeBuild(build);
}

@Test
@Tag("big-it-project")
void test_salt() throws IOException {
SonarScanner build = buildWithCommonProperties("salt");
// salt is not actually a Python 3.12 project. This is to ensure analysis is performed correctly when the parameter is set.
Expand All @@ -252,6 +258,7 @@ void test_specific_rules() throws IOException {
}

@Test
@Tag("big-it-project")
void test_tensorflow() throws IOException {
SonarScanner build = buildWithCommonProperties("tensorflow");
build.setProperty("sonar.sources", "python");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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 org.sonar.python.it;

import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TestDurationMeasureExtension implements BeforeEachCallback, AfterEachCallback, AfterAllCallback {
record TestDuration(String test, Duration duration) {
}

private final static Logger LOGGER = LoggerFactory.getLogger(TestDurationMeasureExtension.class);

private final Map<String, Instant> startTimeMap = new HashMap<>();
private final List<TestDuration> durationList = new ArrayList<>();

private void start(String uuid) {
startTimeMap.put(uuid, Instant.now());
}

private void stop(String uuid, String name) {
Instant start = startTimeMap.get(uuid);
if (start != null) {
Duration duration = Duration.between(start, Instant.now());
durationList.add(new TestDuration(name, duration));
}
}

@Override
public void beforeEach(ExtensionContext context) {
start(context.getUniqueId());
}

@Override
public void afterEach(ExtensionContext context) {
stop(context.getUniqueId(), context.getDisplayName());
}

@Override
public void afterAll(ExtensionContext context) {
LOGGER.info("Test durations:");
durationList.sort(Comparator.comparing(TestDuration::duration).reversed());
for (TestDuration duration : durationList) {
LOGGER.info("{}: {} sec", duration.test(), duration.duration().toSeconds());
}
}
}