[MyPerf4J-101] Fix flaky test testMultiThread4HighRace and testMultiThread4LowRace #101 #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is the purpose of the change
Fix #101
Brief ChangeLog
Test Overview:
Location:
Myperf4j-Base/util/concurrent/AtomicIntHashCounterTest.java
Test :
testMultiThread4HighRace
andtestMultiThread4LowRace
The two test are designed to assess the behavior of a multi-threaded scenario with varying levels of contention, and they use random parameters to perform a large number of iterations to test the stability and correctness of the tested code.
Reason of flakiness:
ExecutorService newFixedThreadPool(int nThreads)
method creates a thread pool that reuses a fixed number of threads operating off a shared unbounded queue. And it will throw error messageIllegalArgumentException
ifnThreads <= 0
.The author initially set the
threadCnt
toavailableProcessors() - 2
to maybe avoid occupying too many computing resources. However, when the machine we use has less than 2 processors, an error will arise.Changes:
availableThreads
to store the number of available processors.threadCnt
to handle cases with different number of available processors.availableThreads - 2
threads, which is consistent with the original code.Verifying this change
Follow this checklist to help us incorporate your contribution quickly and easily:
[MyPerf4J-XXX] Fix NullPointerException when host is null #XXX
. Each commit in the pull request should have a meaningful subject line and body.mvn clean package -Dmaven.test.skip=false
to make sure unit-test pass.