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

Java ITs: Enable parallelization #7570

Closed

Conversation

gregory-paidis-sonarsource
Copy link
Contributor

@gregory-paidis-sonarsource gregory-paidis-sonarsource commented Jul 10, 2023

Part of #7557

Ignore first commit during review, it's a squash of greg/remove-bulk-delete

  • Added parallel option in surefire in pom.xml. Enabled parallelization at a class level.
  • Create a warmup method to populate the plugin cache and avoid race conditions between the test classes.

Copy link
Contributor

@pavel-mikula-sonarsource pavel-mikula-sonarsource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor questions

its/src/test/java/com/sonar/it/shared/TestUtils.java Outdated Show resolved Hide resolved
its/src/test/java/com/sonar/it/shared/TestUtils.java Outdated Show resolved Hide resolved
its/src/test/java/com/sonar/it/shared/TestUtils.java Outdated Show resolved Hide resolved
its/src/test/java/com/sonar/it/shared/TestUtils.java Outdated Show resolved Hide resolved
its/src/test/java/com/sonar/it/shared/Tests.java Outdated Show resolved Hide resolved
@pavel-mikula-sonarsource
Copy link
Contributor

The warm-up doesn't seem to work as expected

[ERROR] analysisWarnings_OldRoslyn(com.sonar.it.csharp.AnalysisWarningsTest)  Time elapsed: 9.46 s  <<< ERROR!
com.sonar.orchestrator.build.BuildFailureException: 
statuses=[-532462766] logs=[SonarScanner for MSBuild 5.13
Using the .NET Framework version of the Scanner for MSBuild
Pre-processing started.
Preparing working directories...
15:12:15.805  Updating build integration targets...
15:12:16.47  Fetching analysis configuration settings...
15:12:17.475  Provisioning analyzer assemblies for cs...
15:12:17.475  Installing required Roslyn analyzers...
15:12:17.491  Processing plugin: csharp version 9.5.0.74119

Unhandled Exception: System.IO.IOException: The file 'C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp\.sonarqube\resources\0\Google.Protobuf.dll' already exists.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at System.IO.Compression.ZipFileExtensions.ExtractToFile(ZipArchiveEntry source, String destinationFileName, Boolean overwrite)
   at System.IO.Compression.ZipFileExtensions.ExtractToDirectory(ZipArchive source, String destinationDirectoryName)
   at System.IO.Compression.ZipFile.ExtractToDirectory(String sourceArchiveFileName, String destinationDirectoryName, Encoding entryNameEncoding)
   at SonarScanner.MSBuild.PreProcessor.Roslyn.EmbeddedAnalyzerInstaller.FetchResourceFromServer(Plugin plugin, String targetDir)
   at SonarScanner.MSBuild.PreProcessor.Roslyn.EmbeddedAnalyzerInstaller.GetPluginResourceFiles(Plugin plugin)
   at SonarScanner.MSBuild.PreProcessor.Roslyn.EmbeddedAnalyzerInstaller.InstallAssemblies(IEnumerable`1 plugins)
   at SonarScanner.MSBuild.PreProcessor.Roslyn.RoslynAnalyzerProvider.FetchAnalyzerPlugins(String language, IEnumerable`1 activeRules)
   at SonarScanner.MSBuild.PreProcessor.Roslyn.RoslynAnalyzerProvider.SetupAnalyzer(BuildSettings teamBuildSettings, IAnalysisPropertyProvider sonarProperties, IEnumerable`1 rules, String language)
   at SonarScanner.MSBuild.PreProcessor.PreProcessor.<FetchArgumentsAndRuleSets>d__9.MoveNext()

@gregory-paidis-sonarsource gregory-paidis-sonarsource force-pushed the greg/enable-parallel-its branch 2 times, most recently from bb198e3 to 18ca9e7 Compare July 12, 2023 08:56
@gregory-paidis-sonarsource
Copy link
Contributor Author

The warm-up doesn't seem to work as expected

Seems like I forgot to delete a BeforeClass, so I had something like this:

@BeforeClass
prepareCache...

@BeforeClass
deleteCache...

And it was deleting the cache after fixing it again :)

@gregory-paidis-sonarsource gregory-paidis-sonarsource force-pushed the greg/enable-parallel-its branch 3 times, most recently from 46c4a18 to e6b6723 Compare July 12, 2023 10:13
Copy link
Contributor

@pavel-mikula-sonarsource pavel-mikula-sonarsource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 2, we need to figure out why it doesn't speed things up on CI before merging

its/pom.xml Outdated
Comment on lines 76 to 77
<!-- <threadCount>16</threadCount>-->
<!-- <perCoreThreadCount>false</perCoreThreadCount>-->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commented stuff should go away before merging

@@ -71,6 +71,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<parallel>classes</parallel>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you testing this with C#-only run to get local data? While excluding the time needed to download SQ zip at the 1st local SQ-cache populating run?

Because from what I saw, surefire is stupid, JUnit is stupid, and they are not any smarter together in test discovery. So "parallel" might not play nicely with "Suite", only with the usual "run all at once" scaffolding

public static void init() throws IOException {
TestUtils.deleteLocalCache();
// Analyze a project to avoid race conditions
analyzeProject(temp, "Empty");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, you can skip the msbuild part. And just run "begin" and "end", where "end" will emit some useless warning that sarif report and other stuff was not configured for C# analysis.

You would just get project dir, execute begin step, execute end step. You can make it a method in TestUtils that

  • would deleteLocalCache() - could be made private then
  • would do the scanner thing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There would also be no more accidental cache deletions

private static final String DIRECTORY = "MetricsTest:foo";
private static final String FILE = "MetricsTest:foo/Class1.cs";
private static final String PROJECT_DIR = "MetricsTest";
private static final String PROJECT_NAME = "MetricsTestIncludeHeaderComment";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static final String PROJECT_NAME = "MetricsTestIncludeHeaderComment";
private static final String PROJECT_KEY = "MetricsTestIncludeHeaderComment";

@sonarcloud
Copy link

sonarcloud bot commented Jul 13, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarcloud
Copy link

sonarcloud bot commented Jul 13, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@pavel-mikula-sonarsource
Copy link
Contributor

Superseded by #7597

@pavel-mikula-sonarsource pavel-mikula-sonarsource deleted the greg/enable-parallel-its branch July 13, 2023 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants