コード例 #1
0
ファイル: timeout_retry.py プロジェクト: tnip/dartlang-sdk
    def GetRemainingTime(self, required=0, msg=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:
            if msg is None:
                msg = 'Timeout expired'
            if remaining > 0:
                msg += (
                    ', wait of %.1f secs required but only %.1f secs left' %
                    (required, remaining))
            self._expired = True
            raise reraiser_thread.TimeoutError(msg)
        return remaining
コード例 #2
0
    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))
コード例 #3
0
    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))