0

I execute test suite through Gradle for the build and it spins up a lots of processes on different ports. Also, failFast is set to true for my test task. So, following happens when I execute my suite:

  1. Suite starts up and spins up processes/servers listening to different ports
  2. Tests in the suite are executed
  3. When one or more tests fails, the suite execution is halted and the build is marked as failed

Now, when failing tests are fixed and the build is eventually run, step 1 (described above) fails with the message that the port is already in use. Also, I am using forkEvery parameter, meaning the previous tests might have more than one JVM running.

Is there any way to clean everything up (in terms of processes and not the physical files) when a build fails through gradle?

Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102

1 Answers1

0

You can add a custom TestListener that stops the processes/servers from (1)

You can reference Spring Boot's FailureRecordingTestListener: https://github.com/spring-projects/spring-boot/blob/master/buildSrc/src/main/java/org/springframework/boot/build/testing/TestFailuresPlugin.java#L57..L95

The basic idea here is that in the afterSuite method, you would stop whatever processes where started/created from (1). Although within the TestListener, you don't have access to the test instance where processes were started from (1). So you'll need to figure out how to stop those processes without having a reference to the original class where it may have defined some things.

Cisco
  • 20,972
  • 5
  • 38
  • 60