Ensure cleanup in TestScheduler

* Ensure cleanup in TestScheduler
* Fix memory leak when running test in SBT.