Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a clean way to stop services #4

Open
nlativy opened this issue Mar 20, 2015 · 2 comments
Open

Provide a clean way to stop services #4

nlativy opened this issue Mar 20, 2015 · 2 comments

Comments

@nlativy
Copy link
Collaborator

nlativy commented Mar 20, 2015

Currently TestingService classes can provide a @BeforeSuite method but there is no corresponding @AfterSuite. This means if you start a bunch of services in the @BeforeSuite method there is no easy way to stop them when you are done testing.

One work around is to attach a JVM shutdown hook in your @BeforeSuite method but this is a bit ugly.

RunListener#testRunFinished in JUnit is basically what we need but a RunListener can only be attached via JUnitCore which would mean forcing users to implement their own main method or use one we provide. That seems much too intrusive.

The proposal in junit-team/junit4#874 may be useful in implementing this but we would need something that could attach the listener while still only requiring the user to add one thing to their tests. Telling people to add the Acai @Rule and also to register a listener for things to work correctly would be too onerous. Probably Acai could be implemented as a listener rather than a rule.

@yurypetrov
Copy link

Hi Nicholas! Are there any updates on this issue? Or maybe you know of some workarounds people have used successfully?

Thanks!

@nlativy
Copy link
Collaborator Author

nlativy commented Dec 5, 2016

No update I'm afraid. The only workaround I've seen used is to add a JVM shutdown hook when starting the service in question, something like:

class BackendTestingService implements TestingService {
  @BeforeSuite public void runServer() {
    Runtime.getRuntime().addShutdownHook(new Thread() {
      @Override public void run() {
        stopServer();
      }
    });
    // ...
  }

  private void stopServer() {
    // ...
  }
}

although I think this approach can be problematic and potentially deadlock when there are other shutdown hooks added by the system under test. For that reason I'm hesitant to add such a feature into Acai proper until there is a more reliable mechanism provided in JUnit that it could be built upon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants