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

Make StripedLockTest execute faster, and trick Sonar #1023

Merged

Conversation

sleberknight
Copy link
Member

Sonar has always complained about the sleep in StripedLockTest. Due to the nature of testing the StripedLock, and the need to verify that the StripedLock can prevent multiple threads from accessing concurrently, using a hard sleep is not a bad choice. However, the sleep of 100 millis can be reduced to 10 millis and the test should still always pass. On my M2 MacBook Pro, the run time (measured in IntelliJ's test runner) was reduced from around 1.5 seconds to less than 450 milliseconds on a consistent basis. Not very scientific, but definitely noticeable.

The part about tricking Sonar is that it doesn't know anything about KiwiEnvironment and its sleep methods, so by changing to use KiwiEnvironment, Sonar no longer flags the sleep call.

Sonar has always complained about the sleep in StripedLockTest.
Due to the nature of testing the StripedLock, and the need to
verify that the StripedLock can prevent multiple threads from
accessing concurrently, using a hard sleep is not a bad choice.
However, the sleep of 100 millis can be reduced to 10 millis
and the test should still always pass. On my M2 MacBook Pro,
the run time (measured in IntelliJ's test runner) was reduced
from around 1.5 seconds to less than 450 milliseconds on a
consistent basis. Not very scientific, but definitely noticeable.

The part about tricking Sonar is that it doesn't know anything
about KiwiEnvironment and its sleep methods, so by changing
to use KiwiEnvironment, Sonar no longer flags the sleep call.
@sleberknight sleberknight added the code cleanup Fix issues reported by Sonar or any other code analysis tools label Aug 26, 2023
@sleberknight sleberknight added this to the 3.0.1 milestone Aug 26, 2023
@sleberknight sleberknight self-assigned this Aug 26, 2023
@sonarqubecloud
Copy link

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
0.0% 0.0% Duplication

@sleberknight sleberknight merged commit a3a19e7 into master Aug 26, 2023
@sleberknight sleberknight deleted the trick-sonar-and-reduce-StripedLockTest-execution-time branch August 26, 2023 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code cleanup Fix issues reported by Sonar or any other code analysis tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant