aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/test/java
diff options
context:
space:
mode:
authorlukasz-jarocki-sonarsource <lukasz.jarocki@sonarsource.com>2024-10-23 09:04:30 +0200
committersonartech <sonartech@sonarsource.com>2024-10-23 20:02:47 +0000
commit24bd8856af66bf2e1148c42279739225b254e84e (patch)
tree8e319d893e2afe046bfa38b1f8e1374158842a85 /sonar-scanner-engine/src/test/java
parent4f5c724f65ee8c9248504a82ea88bbcaa1e0eb09 (diff)
downloadsonarqube-24bd8856af66bf2e1148c42279739225b254e84e.tar.gz
sonarqube-24bd8856af66bf2e1148c42279739225b254e84e.zip
NO-JIRA improved performance of tests in sonar-scanner-engine module
Diffstat (limited to 'sonar-scanner-engine/src/test/java')
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginJarExploderTest.java1
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/qualitygate/QualityGateCheckTest.java1
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ProgressReportTest.java20
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scm/git/CompositeBlameCommandIT.java13
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnScmProviderTest.java48
5 files changed, 52 insertions, 31 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginJarExploderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginJarExploderTest.java
index d300d025570..4ded7fb0901 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginJarExploderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginJarExploderTest.java
@@ -50,6 +50,7 @@ public class ScannerPluginJarExploderTest {
PluginFiles pluginFiles = mock(PluginFiles.class);
when(pluginFiles.createTempDir()).thenReturn(tempDir);
underTest = new ScannerPluginJarExploder(pluginFiles);
+ underTest.setLockRetrySleep(5L);
}
@Test
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/qualitygate/QualityGateCheckTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/qualitygate/QualityGateCheckTest.java
index 0e7e67cb5c5..b31249ff815 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/qualitygate/QualityGateCheckTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/qualitygate/QualityGateCheckTest.java
@@ -71,6 +71,7 @@ class QualityGateCheckTest {
@BeforeEach
void before() {
underTest = new QualityGateCheck(wsClient, analysisMode, reportMetadataHolder, properties);
+ underTest.setPollingIntervalInSeconds(200);
logTester.setLevel(Level.DEBUG);
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ProgressReportTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ProgressReportTest.java
index 4d04a83fd22..71a3fd644a1 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ProgressReportTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ProgressReportTest.java
@@ -20,7 +20,10 @@
package org.sonar.scanner.util;
import java.util.Set;
+import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
+import org.awaitility.Awaitility;
+import org.awaitility.core.ConditionTimeoutException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.DisableOnDebug;
@@ -57,18 +60,25 @@ public class ProgressReportTest {
}
@Test
- public void do_log() throws InterruptedException {
+ public void do_log() {
logTester.setLevel(Level.DEBUG);
underTest.start("start");
underTest.message("Some message");
boolean logged = false;
- Thread.sleep(2000);
while (!logged) {
- logged = logTester.logs().contains("Some message");
+ logged = containsWithRetry("Some message");
}
underTest.stop("stop");
- Thread.sleep(1000);
- assertThat(logTester.logs().stream().anyMatch(s -> Pattern.matches("stop", s))).isTrue();
+ assertThat(containsWithRetry("stop")).isTrue();
+ }
+
+ private boolean containsWithRetry(String message) {
+ try {
+ Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> logTester.logs().contains(message));
+ } catch (ConditionTimeoutException e) {
+ return false;
+ }
+ return true;
}
@Test
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/CompositeBlameCommandIT.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/CompositeBlameCommandIT.java
index 419a205fd52..c95966d6d18 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/CompositeBlameCommandIT.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/CompositeBlameCommandIT.java
@@ -34,6 +34,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.io.CleanupMode;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
@@ -57,19 +58,25 @@ import static org.mockito.Mockito.when;
class CompositeBlameCommandIT {
+ private static final ProcessWrapperFactory processWrapperFactory = new ProcessWrapperFactory();
+ private static final NativeGitBlameCommand nativeGitBlameCommand = new NativeGitBlameCommand(System2.INSTANCE, processWrapperFactory);
+
private final AnalysisWarnings analysisWarnings = mock(AnalysisWarnings.class);
private final BlameCommand.BlameInput input = mock(BlameCommand.BlameInput.class);
private final JGitBlameCommand jGitBlameCommand = new JGitBlameCommand();
- private final ProcessWrapperFactory processWrapperFactory = new ProcessWrapperFactory();
- private final NativeGitBlameCommand nativeGitBlameCommand = new NativeGitBlameCommand(System2.INSTANCE, processWrapperFactory);
-
// In JUnit4, if the cleanup cannot be performed, the test would not fail. This has changed with JUnit5
// As we cannot find the cause of failure during cleanup, we disable it for now
@TempDir (cleanup = NEVER)
private File temp;
+ @BeforeAll
+ public static void setUp() {
+ // locating the git executable is a costly operation that can be done just once for all tests in this class
+ nativeGitBlameCommand.checkIfEnabled();
+ }
+
@ParameterizedTest
@MethodSource("namesOfTheTestRepositoriesWithBlameAlgorithm")
void testThatBlameAlgorithmOutputsTheSameDataAsGitNativeBlame(String folder, BlameAlgorithmEnum blameAlgorithm) throws Exception {
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnScmProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnScmProviderTest.java
index 70bbf25bf22..f753e31bd8f 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnScmProviderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnScmProviderTest.java
@@ -86,10 +86,6 @@ public class SvnScmProviderTest {
@Before
public void before() throws IOException, SVNException {
svnTester = new SvnTester(temp.newFolder().toPath());
-
- Path worktree = temp.newFolder().toPath();
- svnTester.checkout(worktree, "trunk");
- createAndCommitFile(worktree, "file-in-first-commit.xoo");
}
@Test
@@ -119,33 +115,36 @@ public class SvnScmProviderTest {
}
@Test
- public void branchChangedFiles_and_lines_from_diverged() throws IOException, SVNException {
+ public void branchChangedFiles_and_lines_from_diverged() throws IOException, SVNException, InterruptedException {
Path trunk = temp.newFolder().toPath();
svnTester.checkout(trunk, "trunk");
- createAndCommitFile(trunk, "file-m1.xoo");
- createAndCommitFile(trunk, "file-m2.xoo");
- createAndCommitFile(trunk, "file-m3.xoo");
- createAndCommitFile(trunk, "lao.txt", CONTENT_LAO);
+ createFile(trunk, "file-m1.xoo");
+ createFile(trunk, "file-m2.xoo");
+ createFile(trunk, "file-m3.xoo");
+ createFile(trunk, "lao.txt", CONTENT_LAO);
+ svnTester.commit(trunk);
// create branch from trunk
svnTester.createBranch("b1");
// still on trunk
- appendToAndCommitFile(trunk, "file-m3.xoo");
- createAndCommitFile(trunk, "file-m4.xoo");
+ svnTester.appendToFile(trunk, "file-m3.xoo");
+ createFile(trunk, "file-m4.xoo");
+ svnTester.commit(trunk);
Path b1 = temp.newFolder().toPath();
svnTester.checkout(b1, "branches/b1");
Files.createDirectories(b1.resolve("sub"));
- createAndCommitFile(b1, "sub/file-b1.xoo");
- appendToAndCommitFile(b1, "file-m1.xoo");
- deleteAndCommitFile(b1, "file-m2.xoo");
+ createFile(b1, "sub/file-b1.xoo");
+ svnTester.appendToFile(b1, "file-m1.xoo");
+ deleteFile(b1, "file-m2.xoo");
createAndCommitFile(b1, "file-m5.xoo");
- deleteAndCommitFile(b1, "file-m5.xoo");
+ deleteFile(b1, "file-m5.xoo");
svnCopyAndCommitFile(b1, "file-m1.xoo", "file-m1-copy.xoo");
- appendToAndCommitFile(b1, "file-m1.xoo");
+ svnTester.appendToFile(b1, "file-m1.xoo");
+ svnTester.commit(b1);
// modify file without committing it -> should not be included (think generated files)
svnTester.appendToFile(b1, "file-m3.xoo");
@@ -268,8 +267,7 @@ public class SvnScmProviderTest {
}
private void createAndCommitFile(Path worktree, String filename, String content) throws IOException, SVNException {
- svnTester.createFile(worktree, filename, content);
- svnTester.add(worktree, filename);
+ createFile(worktree, filename, content);
svnTester.commit(worktree);
}
@@ -277,14 +275,18 @@ public class SvnScmProviderTest {
createAndCommitFile(worktree, filename, filename + "\n");
}
- private void appendToAndCommitFile(Path worktree, String filename) throws IOException, SVNException {
- svnTester.appendToFile(worktree, filename);
- svnTester.commit(worktree);
+ private void createFile(Path worktree, String filename) throws IOException, SVNException {
+ svnTester.createFile(worktree, filename, filename + "\n");
+ svnTester.add(worktree, filename);
+ }
+
+ private void createFile(Path worktree, String filename, String content) throws IOException, SVNException {
+ svnTester.createFile(worktree, filename, content);
+ svnTester.add(worktree, filename);
}
- private void deleteAndCommitFile(Path worktree, String filename) throws SVNException {
+ private void deleteFile(Path worktree, String filename) throws SVNException {
svnTester.deleteFile(worktree, filename);
- svnTester.commit(worktree);
}
private void svnCopyAndCommitFile(Path worktree, String src, String dst) throws SVNException {