Add error handling and timeout to unit tests