Safer timeout handling and test case