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

[MyPerf4J-101] Fix flaky test testMultiThread4HighRace and testMultiThread4LowRace #101 #1

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,17 @@ public void testSingleThreadV2() {

@Test
public void testMultiThread4HighRace() throws InterruptedException, BrokenBarrierException {
final int threadCnt = Runtime.getRuntime().availableProcessors() - 2;
//final int threadCnt = Runtime.getRuntime().availableProcessors() - 2;
final int availableThreads = Runtime.getRuntime().availableProcessors();
int threadCnt;
if (availableThreads <= 1) {
throw new RuntimeException("Multithreading is not supported on this system with " +
availableThreads + " available processors.");
} else if (availableThreads >= 2 && availableThreads <= 3) {

Choose a reason for hiding this comment

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

Could you please elaborate on why you chose to assign threadCnt = 2 when there are 2 or 3 available processors?
I think the authors might have an issue if both processors get used since their primary motive was to keep 2 processors available for other computing tasks.
In case of 3 available threads, maybe we can assign just one thread since that is what the authors initially intended? (However, I'm not 100% sure if this is the best approach)

threadCnt = 2;
} else {
threadCnt = availableThreads - 2;
}
final ExecutorService executor = Executors.newFixedThreadPool(threadCnt);
int failureTimes = 0;
// final int testTimes = 1024 * 1024;
Expand All @@ -184,7 +194,16 @@ public void testMultiThread4HighRace() throws InterruptedException, BrokenBarrie

@Test
public void testMultiThread4LowRace() throws InterruptedException, BrokenBarrierException {
final int threadCnt = Runtime.getRuntime().availableProcessors() - 2;
final int availableThreads = Runtime.getRuntime().availableProcessors();
int threadCnt;
if (availableThreads <= 1) {
throw new RuntimeException("Multithreading is not supported on this system with " +
availableThreads + " available processors.");
} else if (availableThreads >= 2 && availableThreads <= 3) {
threadCnt = 2;
} else {
threadCnt = availableThreads - 2;
}
final ExecutorService executor = Executors.newFixedThreadPool(threadCnt);
int failureTimes = 0;
// final int testTimes = 1024 * 1024;
Expand Down