Thread wrapping to better handle unit tests