Franz See
01/01/2020, 8:20 AMfun getOrCreateServer() {
...
Runtime.getRuntime().addShutdownHook(Thread(Runnable {
server.shutdown();
}))
return server
}
Then in my tests, I would just call this method to get the server instance and do stuff with it. Then after all tests have executed, this would be called to shutdown the server
In Spek2, this does not get called
How do I what I want to do in Spek2? 🙂raniejade
01/05/2020, 9:51 AMval server by memoized(CachingMode.SCOPE) { ... }
...
afterGroup { server.shutdown() }
Alternatively, memoized
accepts a destructor
parameter - which will be called when the memoized object is not needed anymore.Franz See
01/05/2020, 9:54 AMserver.shutdown()
in the teardown (i.e. afterGroup). Instead, when i start the server, I add the server.shutdown()
in the JVM shutdown hook.
That's because i want to start the server once for ALL the tests, and shut it down once ALL the tests are done
If I put the shutdown in the teardown, it will start and stop the server for every test suite.raniejade
01/05/2020, 10:22 AMSystem.exit(0)
after all tests are finish - because lingering non-daemon threads can block the jvm from shutting down (which can cause the shutdown hooks not to be called).Franz See
01/05/2020, 11:35 AM