jaxrs-analyzer icon indicating copy to clipboard operation
jaxrs-analyzer copied to clipboard

Failing test

Open hindsholm opened this issue 9 years ago • 8 comments

I am unable to build jaxrs-analyzer due to a failing test:

test(com.sebastian_daschner.jaxrs_analyzer.analysis.ProjectAnalyzerTest)`  Time elapsed: 1.357 sec  <<< FAILURE!
org.junit.ComparisonFailure: expected:<[rest]> but was:<[]>

This is on a fresh clone from master.

My setup should be up to date:

[morten@t430s] 15:21 $ mvn -v
Apache Maven 3.3.9 (NON-CANONICAL_2015-11-23T13:17:27+03:00_root; 2015-11-23T11:17:27+01:00)
Maven home: /opt/maven
Java version: 1.8.0_121, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-jdk/jre
Default locale: en_DK, platform encoding: UTF-8
OS name: "linux", version: "4.10.6-1-arch", arch: "amd64", family: "unix"`

The same test fails also on a similar setup on Windows 7.

Please let me know if I should provide more information.

hindsholm avatar Mar 31 '17 13:03 hindsholm

Hi @hindsholm,

I've just tested here (just cloned master) and its all green, both via IDE and maven, here's my setup:

Apache Maven 3.3.9
Maven home: /usr/share/maven
Java version: 1.8.0_121, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-66-generic", arch: "amd64", family: "unix"

Anyone else experiencing this?

rmpestano avatar Mar 31 '17 14:03 rmpestano

I also thought it was strange that nobody else had reported this, so it may be just me :) But on the other hand, I get the exact same error on both Linux and Windows and I also tried both OpenJDK and Oracle JDK, and I am running out of ideas of what to try...

hindsholm avatar Apr 01 '17 13:04 hindsholm

That specific test is a concurrency error when running the ProjectAnalyzerTest and some other. I've excluded parallel tests to not run via Maven, do you use multiple threads in you mvn command?

Btw, we should also make the tests runnable in parallel (there is some static variable that needs to be modified which I can't remember right away...)

sdaschner avatar Apr 02 '17 20:04 sdaschner

Thank you @sdaschner - your comment led me on the right track. I learned through some googling that since jaxrs-analyzer uses an older version (2.10) of surefire-plugin, you can ensure that tests are run sequentially by setting forkMode like in:

mvn -DforkMode=always clean install

and the project builds just fine.

With a newer Surefire you could actually specify this behavior through an annotation as described in the official docs:

Since of Surefire 2.18, you can apply the JCIP annotation @net.jcip.annotations.NotThreadSafe on the Java class of JUnit test (test class, Suite, Parameterized, etc.) in order to execute it in single Thread instance.

I'll close the issue since it has now been solved.

hindsholm avatar Apr 02 '17 22:04 hindsholm

@hindsholm @sdaschner I'd like to reopen this issue since it still occurs without the workaround (specifying -DforkMode=always). Can please one of you do that? (I don't have permission)

One fix would be to change the surefire configuration in the pom.xml to use that option. Another would be to adopt JCIP annotation. It is unfortunate that Surefire made it so hard to run tests sequentially. Parallel test running is a bad idea, as it introduces random variability (tests should always pass or always fail)...

abstratt avatar Jul 25 '17 19:07 abstratt

surefire has a ThreadSafe annotation, the specifics escape me. i used @Ignore

jnorthrup avatar Apr 04 '18 16:04 jnorthrup

I confirm, this test is still failing (java8, mvn 3.5.5)

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 1.052 sec <<< FAILURE!
test(com.sebastian_daschner.jaxrs_analyzer.analysis.ProjectAnalyzerTest)  Time elapsed: 1.051 sec  <<< FAILURE!
org.junit.ComparisonFailure: expected:<[rest]> but was:<[]>
        at org.junit.Assert.assertEquals(Assert.java:115)
        at org.junit.Assert.assertEquals(Assert.java:144)
        at com.sebastian_daschner.jaxrs_analyzer.analysis.ProjectAnalyzerTest.test(ProjectAnalyzerTest.java:80)

config:

Java version: 1.8.0_201, vendor: Oracle Corporation, runtime: C:\Localdata\ProgramFiles\Java\jdk1.8.0_201\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
Picked up _JAVA_OPTIONS: -Djava.net.preferIPv4Stack=true

dizzzz avatar Jul 03 '19 08:07 dizzzz

@sdaschner : I have created a PR to fix this concurrency issue with running the tests. I would be glad to support the project. That PR is #196

sichgeis avatar Feb 05 '20 13:02 sichgeis