def GetRemainingTime(self, required=0, suffix=None): """Get the remaining time before the thread times out. Useful to send as the |timeout| parameter of async IO operations. Args: required: minimum amount of time that will be required to complete, e.g., some sleep or IO operation. msg: error message to show if timing out. Returns: The number of seconds remaining before the thread times out, or None if the thread never times out. Raises: reraiser_thread.TimeoutError if the remaining time is less than the required time. """ remaining = self._watcher.GetRemaining() if remaining is not None and remaining < required: msg = 'Timeout of %.1f secs expired' % self._watcher.GetTimeout() if suffix: msg += suffix raise reraiser_thread.TimeoutError(msg) return remaining
def testMethodDecoratorTranslatesReraiserExceptions(self): test_obj = self._MethodDecoratorTestObject(self) exception_desc = 'Reraiser thread timeout error' with self.assertRaises(device_errors.CommandTimeoutError) as e: test_obj.alwaysRaisesProvidedException( reraiser_thread.TimeoutError(exception_desc)) self.assertEquals(exception_desc, str(e.exception))
def testExplicitDecoratorTranslatesReraiserExceptions(self): """Tests that the explicit decorator translates reraiser exceptions.""" @decorators.WithExplicitTimeoutAndRetries(30, 10) def alwaysRaisesProvidedException(exception): raise exception exception_desc = 'Reraiser thread timeout error' with self.assertRaises(device_errors.CommandTimeoutError) as e: alwaysRaisesProvidedException( reraiser_thread.TimeoutError(exception_desc)) self.assertEquals(exception_desc, str(e.exception))