Alisha-Anaum opened a new pull request, #2242:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/2242

   ### What changes were proposed in this pull request?
   
   I observe a previous suggested fix injected some delay, but I believe that 
fix might be unstable in a CI environment or when run on different machines, 
given the dependency on some constant wait time. I suggest a new way to fix the 
test by adding some synchronization for the test execution only. I at first 
identify the code location whose slow execution leads to the flaky test 
failure, I found 
elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/concurrent/ElasticJobExecutorServiceTest.java#52
 slows the execution makes assertion failure. Hence, I introduce one variable 
in this test class that is only there to provide some synchronization. 
Basically, until these statements are executed, I force the thread that the 
test runs to wait before it accesses the assertion values. The waiting location 
is  after 
https://github.com/apache/shardingsphere-elasticjob/blob/a7042cf4872d784d619e4560cdfa0f92b0311965/elasticjob-infra/elasticjob-infra-commo
 
n/src/test/java/org/apache/shardingsphere/elasticjob/infra/concurrent/ElasticJobExecutorServiceTest.java#L57.
 
   
   ### Why are the changes needed?
   
   This test is sometimes failing because in the code-under-test some threads 
slows down the return of workQueue.size() . Hence, the error occurs.
   
   Changes proposed in this pull request:
   
   Failure-Log:
   Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 2.698 s <<< 
FAILURE! - in 
org.apache.shardingsphere.elasticjob.infra.concurrent.ElasticJobExecutorServiceTest
   [ERROR] 
assertCreateExecutorService(org.apache.shardingsphere.elasticjob.infra.concurrent.ElasticJobExecutorServiceTest)
 Time elapsed: 2.654 s <<< FAILURE!
   java.lang.AssertionError:
   
   Expected: is <1>
   but: was <0>
   at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
   at org.junit.Assert.assertThat(Assert.java:956)
   at org.junit.Assert.assertThat(Assert.java:923)
   at 
org.apache.shardingsphere.elasticjob.infra.concurrent.ElasticJobExecutorServiceTest.assertCreateExecutorService(ElasticJobExecutorServiceTest.java:46)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:498)
   at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
   at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
   at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
   at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
   at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
   at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
   at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
   at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
   at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
   at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
   at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
   at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
   at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
   at 
org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:365)
   at 
org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:273)
   at 
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)
   at 
org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:159)
   at 
org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
   at 
org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)
   at 
org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
   at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)
   
   
   ### How was this patch tested?
   I run this test more than 1000 times and the test always passes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to