Fixed shutdown logic in task unit tests.