perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.63k stars 1.56k forks source link

Service::stop() does not allow me to know when the job is done #1013

Closed chibenwa closed 5 years ago

chibenwa commented 6 years ago

Hi everyone.

One of my collegues recently wrote a test about default exception handling, involving registration of exception handler. Curiously, test order impacted test correctness (breaking test isolation) leading to a funny debug session.

It turned out the Service::stop is run in an other thread. Thus our test suite was starting a new test before the stop operation finished. A data race between the new test and the old test resulted in the handler of the new test being deleted by the old test....

Needless to say, I need to achieve strong test isolation. My proposal is simple: return Future that the user can await on to ensure cleaning process finished.

I will have a pull request for this.

simonreye commented 6 years ago

I hit this problem today as well.

May I suggest we keep stop() as is and have an additional function stopAndWait() (or something like that) for those who don't want the stopping calls to be done in a separate thread.

jakaarl commented 6 years ago

See PR #730 .

redcatbear commented 6 years ago

:+1: for addressing this. Ran into this problem with automatic integration tests where I have to start and stop regularly. My current workaround using a wait() is not very satisfying.

meow-sokovykh commented 5 years ago

Isn't that fixed with awaitStop() in 2.8.0? I think, that issue should be closed

chibenwa commented 5 years ago

Yes that is adresses.