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

Flaky test testMultiThread4HighRace and testMultiThread4LowRace #101

Closed
CaseyPan opened this issue Oct 13, 2023 · 1 comment · May be fixed by CaseyPan/MyPerf4J#1
Closed

Flaky test testMultiThread4HighRace and testMultiThread4LowRace #101

CaseyPan opened this issue Oct 13, 2023 · 1 comment · May be fixed by CaseyPan/MyPerf4J#1
Labels
bug Something isn't working

Comments

@CaseyPan
Copy link

Bug Description

final int threadCnt = Runtime.getRuntime().availableProcessors() - 2;

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 message IllegalArgumentException if nThreads <= 0.
The author initially set the threadCnt to availableProcessors() - 2 to maybe avoid occupying too many computing resources. However, when the machine we use has less than 2 processors, an error will arise.

Environment

  • MyPerf4J version - latest
  • JDK - OpenJDK 11
  • OS - Linux

Steps to Reproduce

  1. Install the package
    mvn install -pl MyPerf4J-Base -am -DskipTests
    
  2. The test failed by running the following command:
    mvn -pl MyPerf4J-Base test -Dtest=cn.myperf4j.base.util.concurrent.AtomicIntHashCounterTest#testMultiThread4HighRace
    
    or
    mvn -pl MyPerf4J-Base test -Dtest=cn.myperf4j.base.util.concurrent.AtomicIntHashCounterTest#testMultiThread4LowRace
    

Error message:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running cn.myperf4j.base.util.concurrent.AtomicIntHashCounterTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.077 sec <<< FAILURE!
testMultiThread4HighRace(cn.myperf4j.base.util.concurrent.AtomicIntHashCounterTest)  Time elapsed: 0.015 sec  <<< ERROR!
java.lang.IllegalArgumentException
        at java.base/java.util.concurrent.ThreadPoolExecutor.<init>(ThreadPoolExecutor.java:1293)
        at java.base/java.util.concurrent.ThreadPoolExecutor.<init>(ThreadPoolExecutor.java:1179)
        at java.base/java.util.concurrent.Executors.newFixedThreadPool(Executors.java:92)
        at cn.myperf4j.base.util.concurrent.AtomicIntHashCounterTest.testMultiThread4HighRace(AtomicIntHashCounterTest.java:176)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
        at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
        at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
        at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
        at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
        at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:242)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:137)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
        at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)


Results :

Tests in error: 
  testMultiThread4HighRace(cn.myperf4j.base.util.concurrent.AtomicIntHashCounterTest)

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.716 s
[INFO] Finished at: 2023-10-12T23:20:52-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project MyPerf4J-Base: There are test failures.
[ERROR] 
[ERROR] Please refer to /home/ycp2/MyPerf4J/MyPerf4J-Base/target/surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

(The error message is the same for testMultiThread4LowRace)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants