Skip to content

SLCORE-2286 Factorize analysis utilities for ITs, reduce flaky tests#1981

Merged
damien-urruty-sonarsource merged 1 commit intomasterfrom
task/dam/fix-flaky-its
Apr 13, 2026
Merged

SLCORE-2286 Factorize analysis utilities for ITs, reduce flaky tests#1981
damien-urruty-sonarsource merged 1 commit intomasterfrom
task/dam/fix-flaky-its

Conversation

@damien-urruty-sonarsource
Copy link
Copy Markdown
Contributor

Use a single Utils class to trigger analysis, wait for completion and for issues/hotpots raise calls, consume and return issues.

@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod bot changed the title Factorize analysis utilities for ITs, reduce flaky tests SLCORE-2286 Factorize analysis utilities for ITs, reduce flaky tests Apr 10, 2026
@hashicorp-vault-sonar-prod
Copy link
Copy Markdown

hashicorp-vault-sonar-prod bot commented Apr 10, 2026

SLCORE-2286

@damien-urruty-sonarsource damien-urruty-sonarsource marked this pull request as ready for review April 10, 2026 17:14
@sonar-review-alpha
Copy link
Copy Markdown

sonar-review-alpha bot commented Apr 10, 2026

Summary

This PR extracts common analysis patterns used across multiple integration tests into a reusable utility class, reducing code duplication and improving test reliability.

Key changes:

  • New AnalysisUtils class with methods to analyze files and wait for issues/hotspots to be raised, handling file system updates and async completion waits
  • MockSonarLintRpcClientDelegate refactored for thread safety: switched to ConcurrentHashMap and changed getter methods to take* operations that consume/remove data
  • Five test classes (StandaloneTests, SonarCloudTests, etc.) simplified to use the new utility instead of duplicating analysis setup logic

Why it helps: The take pattern ensures results are consumed only once, eliminating race conditions where tests could read stale data or miss notifications. Centralizing this logic reduces the likelihood of test flakiness and makes the test code more maintainable.

What reviewers should know

Start here: Review AnalysisUtils.java first—it's the core of this refactor. The two key methods (analyzeAndAwaitIssues and analyzeAndAwaitHotspots) encapsulate the exact sequence: file system update → analysis request → await with Objects::nonNull check → flatten results.

Watch for:

  • The takeRaisedIssues() pattern in MockSonarLintRpcClientDelegate uses remove() instead of get(), consuming data on first access. Verify test cleanup doesn't inadvertently rely on accessing the same data twice.
  • Thread safety: ConcurrentHashMap is now used, which is necessary if tests run in parallel. Check if the test suite is configured for parallel execution.

Why changes look safe: The utility properly handles Awaitility's until() with a null-check (Objects::nonNull), matching the previous pattern of "wait until data appears". The refactored tests call the utility unchanged, so behavior should be identical but more reliable.


  • Generate Walkthrough
  • Generate Diagram

🗣️ Give feedback

sonar-review-alpha[bot]

This comment was marked as resolved.

Use a single Utils class to trigger analysis, wait for completion and for issues/hotpots raise calls, consume and return issues.
@sonarqube-next
Copy link
Copy Markdown

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
0 Dependency risks
No data about Coverage
No data about Duplication

See analysis details on SonarQube

Copy link
Copy Markdown

@sonar-review-alpha sonar-review-alpha bot left a comment

Choose a reason for hiding this comment

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

LGTM! ✅

🗣️ Give feedback

Copy link
Copy Markdown
Member

@nquinquenel nquinquenel left a comment

Choose a reason for hiding this comment

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

LGTM

@damien-urruty-sonarsource damien-urruty-sonarsource merged commit c5957e5 into master Apr 13, 2026
16 checks passed
@damien-urruty-sonarsource damien-urruty-sonarsource deleted the task/dam/fix-flaky-its branch April 13, 2026 21:44
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