0

In a multi-module maven project, I want to print the thread-dump and fail the test when a test timeout is reached. So to achieve this I have used a combination of TimedoutTestsListener and surefire listener property.

I am using Jenkins so fail-on-end is set to true so that all non-impacted tests continue to run as mentioned here.

So, is it possible to fail the build immediately only when timeout is reached and in other failure cases fail in the end?

  • JUnit - 4.12
  • Maven - 3.5
  • Surefire - 2.22.2
  • Jave - 8
tuk
  • 5,941
  • 14
  • 79
  • 162

1 Answers1

0

This has been answered in the maven email group

to fail the build immediately when timeout is reached

This feature exists for years: http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#forkedProcessTimeoutInSeconds http://maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html#forkedProcessTimeoutInSeconds

to fail the ... when someone presses abort button on the jenkins

This also exists with several alternatives (changed across the versions). See the detailed page http://maven.apache.org/surefire/maven-failsafe-plugin/examples/shutdown.html

If your Jenkins sends the SIGTERM signal into the Maven process (same as CTRL+C) then the standard input stream in process pipe becomes closed and the EOFException is caugh byt the forked JVM and shutdown is called: http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#shutdown maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html#shutdown If you want to kill the JVM, you can reconfigure the default behavior.

If your Jenkins sends SIGTERM to the Maven process then enable the process checker, see more details in the documentaion: http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#enableProcessChecker http://maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html#enableProcessChecker

Did it help?

Here is the FAQ: http://maven.apache.org/surefire/maven-failsafe-plugin/faq.html

Feel free to ask any questions if you have a problem with this topic.

If you are using surefire 3.0.0-M4 then thread-dump can be found in target/surefire-reports as explained here.

tuk
  • 5,941
  • 14
  • 79
  • 162