Why does running failing tests within a Spring application context cause my Jenkins build to crash?
I am using Ant to build my application and run JUnit tests on Jenkins.
I have not experienced any problems while running my Ant build within Eclipse, with or without failing tests.
However, when I try to run the build with Jenkins, the build fails without recording an exception when it has finished running the JUnit tests:
...
[junit] INFO: Executing Stored Procedure with parameters {#pivoting=1, #ignoreReference=0}
[junit] Tests run: 7, Failures: 1, Errors: 0, Time elapsed: 7.831 sec
[junit] Sep 22, 2015 4:23:57 PM org.springframework.context.support.AbstractApplicationContext doClose
[junit] INFO: Closing org.springframework.context.support.GenericApplicationContext#8a590d1:
startup date [Tue Sep 22 16:23:52 BST 2015]; root of context hierarchy
BUILD FAILED
E:\Jenkins\jobs\workspace\AntBuilds\build.xml:336: Tests failed
Total time: 16 seconds
Build step 'Invoke Ant' marked build as failure
Archiving artifacts
Recording test results
Finished: FAILURE
The output above is unexpected, as I have configured the build to be simply UNSTABLE if tests fail, and I have configured a JaCoCo report to be published after the tests have been run.
Usually I would see something more like:
[junit] INFO: Closing org.springframework.context.support.GenericApplicationContext#6a38e598: display name [org.springframework.context.support.GenericApplicationContext#6a38e598]; startup date [Tue Sep 22 16:01:10 BST 2015]; root of context hierarchy
[junit] Tests FAILED
[jacoco:report] Loading execution data file E:\Jenkins\jobs\jacoco.exec
[jacoco:report] Writing bundle 'Coverage Report' with 117 classes
...etc
Removing the failing tests allows the build to continue as normal:
BUILD SUCCESSFUL
Total time: 36 seconds
Archiving artifacts
Recording test results
[JaCoCo plugin] Collecting JaCoCo coverage data...
[JaCoCo plugin] **/**.exec;**/dist/WEB-INF/classes;**/src; locations are configured
[JaCoCo plugin] Number of found exec files for pattern **/**.exec: 1
[JaCoCo plugin] Saving matched execfiles: E:\Jenkins\jobs\myJob\jacoco.exec
... etc
My answer so far
I have been successfully building other applications on Jenkins. The difference is that these tests are marked with a Spring application context:
#ContextConfiguration(locations="file:WEB-INF/MyJob-servlet.xml")
#RunWith(SpringJUnit4ClassRunner.class)
I have been wondering if Jenkins fails to close the Application Context when tests fail, as this line appears for the failed build just before the 'BUILD FAILED' message:
Closing org.springframework.context.support.GenericApplicationContext#8a590d1:
startup date [Tue Sep 22 16:23:52 BST 2015]; root of context hierarchy
I have needed to upgrade to:
JUnit-4.4
spring-integration-test-2.1.3.RELEASE
Is this hunch correct? If so, is this a bug with Jenkins / Spring / incompatible versions, or is my implementation incorrect?
If a test fails then Jenkins fails the build by default. The stability of the build is calculated by how much builds have been failing recently. So if failing tests didn't cause your build to fail, then test would have no influence on stability, and then you can't do stuff like email people that the build failed and what commit caused it, and what test failed, which is highly useful.
Related
I dug around option and source code but still unsure how to debug a bazel build, java specifically.
Also anyone know how I can change bazel, build it locally and use it on builds to verify. I found bazel invocation:
exec -a "$0" "${BAZEL_REAL}" "$#"
where BAZEL_REAL is a binary: /usr/local/Cellar/bazel/0.15.2/libexec/bin/bazel-real
But this doesn't explain closely how it starts and how I can debug it...
Like is it possible to jump in and debug com.google.devtools.build.lib.bazel.rules.java.BazelJavaLibraryRule while building my code? Like if I build my code with Maven, I can do mvnDebug.
bazel build -s
➜ bazel git:(master) ✗ bazel build //examples/java-native/src/main/java/com/example/myproject:hello-world -s
BAZEL_REAL==/usr/local/Cellar/bazel/0.15.2/libexec/bin/bazel-real
INFO: Analysed target //examples/java-native/src/main/java/com/example/myproject:hello-world (15 packages loaded).
INFO: Found 1 target...
Target //examples/java-native/src/main/java/com/example/myproject:hello-world up-to-date:
bazel-bin/examples/java-native/src/main/java/com/example/myproject/hello-world.jar
bazel-bin/examples/java-native/src/main/java/com/example/myproject/hello-world
INFO: Elapsed time: 4.943s, Critical Path: 0.29s
INFO: 0 processes.
INFO: Build completed successfully, 2 total actions
nevermind me, https://www.bazel.build/contributing.html#setting-up-your-coding-environment has the info I need.
Basically for starter
bazel --host_jvm_debug build //:*
the order of args are significant. For example below will NOT work
bazel build //:* --host_jvm_debug
To debug worker's jvm, get the command with bazel build -s, then append the remote debug startup opts.
I am running Jenkins job and afterwards I am getting timeout error:
get.hudson.release.version:
get.svn.build.version:
[echo] Determinating build version
[echo] Check SVN info for URL:
[svn] started ... Build timed out (after 30 minutes). Marking the build as failed. Build was aborted Archiving artifacts
I've checked configuration of job. It looks fine. URL is working. I can get it via the browser. How can I investigate/understand the root cause of problem?
I am creating a game with JavaFX with a team. Everything is going fine, except for one thing. We have created an automated GUI test, which we got to run on travis by running an Xvfb display:
before_install:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16"
However, this display does not support 3D. In the Travis log, there are literally thousands of lines saying the following:
WARNING: System can't support ConditionalFeature.SCENE3D
Sep 15, 2015 11:16:00 AM javafx.scene.shape.Shape3D <init>
Having thousands of warnings spammed in the log doesn't affect any of our tests. But when we added a bunch more objects, Travis cut off our build because the log file was getting too long:
WARNING: System can't support ConditionalFeature.SCENE3D
Sep 15, 2015 11:16:00 AM javafx.scene.shape.Shape3D <init>
The log length has exceeded the limit of 4 Megabytes (this usually means that test suite is raising the same exception over and over).
The build has been terminated.
Question: Does anyone know a way to support 3D on these kind of headless GUI tests?
Alternative: How to turn off these Warnings so that the log file won't become this long?
If more information is needed to answer this question, please ask! :)
One way could be to make sure (either in your code or in your test) that only that code is executed that is supported:
http://docs.oracle.com/javase/8/javafx/api/javafx/application/Platform.html#isSupported-javafx.application.ConditionalFeature-
I start working on older Spring application and when I start it, it produces such log messages (~100 messages):
2015-02-10 15:53:11,757 INFO
[org.springframework.context.annotation.AnnotationConfigApplicationContext:510]
- Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#50533643:
startup date [Tue Feb 10 15:53:11 CET 2015]; root of context hierarchy
And terminates with this exception:
Exception in thread "main" java.lang.NoClassDefFoundError:
org.springframework.beans.FatalBeanException
I am running it in IntelliJ IDEA and I use Maven for dependency management.
It never happed before - what could be wrong?
I recommend to build it again with maven and build a new IDEA project. This problem is a dependency issue.
To build:
mvn clean install
and to create new IDEA project
mvn idea:clean idea:idea
This is a maven build, running on Jenkins. Version numbers listed at the end of this post. I'm trying to figure out how to abort my build when I get an error in the generate-test-resources phase.
Requirement: During maven's generate-test-resources phase, I have processes that run on a remote server (iSeries). From those calls, I retrieve a success flag (true or false). When I get false, I'd like to mark the ENTIRE build as BUILD FAILURE, and abort the build.
The code I run in generate-test-resources is in Java, but it submits jobs to the iSeries, and the real work is done in those submitted jobs.
Rational: My primary purpose of this build it to execute JUnit test cases. The generate-test-resources phase calls processes to initialize the test environment. If the generate-test-resources phase is not 100% successful, the tests will likely pass, but those results would be invalid.
Furthermore, when generate-test-resources has issues, but all the test cases pass, Jenkins reports BUILD SUCCESS. Very strange.
Example: Here is an example from my log. I know that my call to MY_BUILD_COMMAND calls back to the server correctly, and it is successful most days. But when there is an error, I need to trap it. Notice I have the status at "success? = false"
23:11:33.982 INFO BuildTestEnvironment | -- Begin BuildTestEnvironment ---------------------
23:11:35.224 INFO BuildTestEnvironment | Connected to VQ_INSCI10 as VQCINSCI10
23:11:35.292 INFO qcmdExc | CALL QCMDEXC('MY_BUILD_COMMAND', 16)
23:11:35.621 FATAL qcmdExc | [CPF0006] Errors occurred in command.
java.sql.SQLException: [CPF0006] Errors occurred in command.
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:646)
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:617)
at com.ibm.as400.access.AS400JDBCStatement.commonPrepare(AS400JDBCStatement.java:1401)
at com.ibm.as400.access.AS400JDBCStatement.execute(AS400JDBCStatement.java:1755)
at main.java._tools.QcmdExc.run(QcmdExc.java:33)
at main.java._tools.BuildTestEnvironment.main(BuildTestEnvironment.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:293)
at java.lang.Thread.run(Thread.java:744)
23:11:35.624 INFO BuildTestEnvironment | success? = false
And then, at the end of the log:
[INFO] --- maven-install-plugin:2.3.1:install (default-install) # VSP_UnitTest ---
[INFO] Installing /root/.jenkins/workspace/VSP_v10_Continuous/target/VSP_UnitTest-1.0-SNAPSHOT.jar to /root/.m2/repository/VSP_UnitTest/VSP_UnitTest/1.0-SNAPSHOT/VSP_UnitTest-1.0-SNAPSHOT.jar
[INFO] Installing /root/.jenkins/workspace/VSP_v10_Continuous/pom.xml to /root/.m2/repository/VSP_UnitTest/VSP_UnitTest/1.0-SNAPSHOT/VSP_UnitTest-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:09:12.515s
[INFO] Finished at: Mon Sep 22 00:20:38 EDT 2014
[INFO] Final Memory: 28M/393M
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[JENKINS] Archiving /root/.jenkins/workspace/VSP_v10_Continuous/pom.xml to VSP_UnitTest/VSP_UnitTest/1.0-SNAPSHOT/VSP_UnitTest-1.0-SNAPSHOT.pom
[JENKINS] Archiving /root/.jenkins/workspace/VSP_v10_Continuous/target/VSP_UnitTest-1.0-SNAPSHOT.jar to VSP_UnitTest/VSP_UnitTest/1.0-SNAPSHOT/VSP_UnitTest-1.0-SNAPSHOT.jar
channel stopped
Email was triggered for: Always
Sending email for trigger: Always
Sending email to: email#email.com
Finished: UNSTABLE
Versions in use:
maven-complier-plugin = 2.3.2
exec-maven-plugin = 1.3
Jenkins ver. 1.539
JUnit 4.11
The exec-maven-plugin exec goal has a successCodes element. Typically on a Unix system, a command that runs successfully returns 0. I'm wondering if the false returned by the test setup is being interpreted as 0 which would indicate Success as far as the plugin is concerned. Try adding <successCodes>1</successCodes> to the plugin configuration and see if that causes the build to fail as desired.