Ejemplo n.º 1
0
 def timeoutConnection(self):
     """
     Close the connection in case of timeout.
     """
     for cmd in self._current:
         cmd.fail(TimeoutError("Connection timeout"))
     self.transport.loseConnection()
Ejemplo n.º 2
0
    def test_remove_security_groups_raises_http_timeout(self):
        """Verify that a timeout in txaws raises an appropiate error.

        This is an example of a scenario where txaws may not raise an
        EC2Error, but will instead raise some other error.
        """
        system_state = MockInstanceState(self, ["i-amkillable"], [0],
                                         [["shutting-down"], ["shutting-down"],
                                          ["shutting-down"], ["terminated"]])

        self.ec2.describe_instances("i-amkillable")
        self.mocker.call(system_state.get_round)
        self.mocker.count(4)

        self.ec2.delete_security_group("juju-moon-0")
        self.mocker.result(
            fail(
                TimeoutError(
                    "Getting https://x.example.com?Action=DeleteSecurityGroup"
                    "&etc=andsoforth took longer than 30 seconds.")))
        self.mocker.replay()

        provider = self.get_provider()
        ex = yield self.assertFailure(
            remove_security_groups(provider, ["i-amkillable"]), TimeoutError)
        self.assertEquals(
            str(ex), "Getting https://x.example.com?Action=DeleteSecurityGroup"
            "&etc=andsoforth took longer than 30 seconds.")
Ejemplo n.º 3
0
    def runReactor(self, reactor, timeout=None):
        """
        Run the reactor for at most the given amount of time.

        @param reactor: The reactor to run.

        @type timeout: C{int} or C{float}
        @param timeout: The maximum amount of time, specified in seconds, to
            allow the reactor to run.  If the reactor is still running after
            this much time has elapsed, it will be stopped and an exception
            raised.  If C{None}, the default test method timeout imposed by
            Trial will be used.  This depends on the L{IReactorTime}
            implementation of C{reactor} for correct operation.

        @raise TimeoutError: If the reactor is still running after C{timeout}
            seconds.
        """
        if timeout is None:
            timeout = self.getTimeout()

        timedOut = []
        def stop():
            timedOut.append(None)
            reactor.stop()

        reactor.callLater(timeout, stop)
        reactor.run()
        if timedOut:
            raise TimeoutError(
                "reactor still running after %s seconds" % (timeout,))
Ejemplo n.º 4
0
    def test_continuesWhenAllRootHintsFail(self):
        """
        The L{root.Resolver} is eventually created, even if all of the root hint
        lookups fail. Pending and new lookups will then fail with
        AttributeError.
        """
        stubResolver = StubResolver()
        deferredResolver = root.bootstrap(stubResolver)
        results = iter(stubResolver.pendingResults)
        d1 = next(results)
        for d in results:
            d.errback(TimeoutError())
        d1.errback(TimeoutError())

        def checkHints(res):
            self.assertEqual(deferredResolver.hints, [])
        d1.addBoth(checkHints)

        self.addCleanup(self.flushLoggedErrors, TimeoutError)
Ejemplo n.º 5
0
def sync_wait(deferred, timeout=10):
    if not isinstance(deferred, Deferred):
        return deferred

    queue = Queue()
    deferred.addBoth(queue.put)

    try:
        result = queue.get(True, timeout)
    except Empty:
        raise TimeoutError("Command timed out")

    if isinstance(result, Failure):
        result.raiseException()
    return result
Ejemplo n.º 6
0
 def _request_timeout(self, tx_tid):
     self.log.debug("_request_timeout", tx_tid=tx_tid)
     if tx_tid in self._requests:
         req = self._requests[
             tx_tid]  # (0: timestamp, 1: defer, 2: frame, 3: timeout, 4: retry, 5: delayedCall)
         frame = req[2]
         timeout = req[3]
         retry = req[4]
         if retry > 0:
             retry -= 1
             self.send(frame, timeout, retry)
         else:
             d = req[1]
             d.errback(
                 failure.Failure(
                     TimeoutError(timeout,
                                  "Send OMCI TID -{}".format(tx_tid))))
Ejemplo n.º 7
0
    def test_continuesWhenSomeRootHintsFail(self):
        """
        The L{root.Resolver} is eventually created, even if some of the root
        hint lookups fail. Only the working root hint IP addresses are supplied
        to the L{root.Resolver}.
        """
        stubResolver = StubResolver()
        deferredResolver = root.bootstrap(stubResolver)
        results = iter(stubResolver.pendingResults)
        d1 = next(results)
        for d in results:
            d.callback('192.0.2.101')
        d1.errback(TimeoutError())

        def checkHints(res):
            self.assertEqual(deferredResolver.hints, ['192.0.2.101'] * 12)
        d1.addBoth(checkHints)
Ejemplo n.º 8
0
    def _request_failure(self, value, tx_tid, high_priority):
        """
        Handle a transmit failure. Rx Timeouts are handled on the 'dc' deferred and
        will call a different method that may retry if requested.  This routine
        will be called after the final (if any) timeout or other error

        :param value: (Failure) Twisted failure
        :param tx_tid: (int) Associated Tx TID
        """
        index = self._get_priority_index(high_priority)

        if self._tx_request[index] is not None:
            tx_frame = self._tx_request[index][OMCI_CC.REQUEST_FRAME]
            tx_frame_tid = tx_frame.fields['transaction_id']

            if tx_frame_tid == tx_tid:
                timeout = self._tx_request[index][OMCI_CC.REQUEST_TIMEOUT]
                dc = self._tx_request[index][OMCI_CC.REQUEST_DELAYED_CALL]
                self._tx_request[index] = None

                if dc is not None and not dc.called and not dc.cancelled:
                    dc.cancel()

                if isinstance(value, failure.Failure):
                    value.trap(CancelledError)
                    self._rx_timeouts += 1
                    self._consecutive_errors += 1
                    if self._consecutive_errors == 1:
                        reactor.callLater(0, self._publish_connectivity_event,
                                          False)

                    self.log.debug('timeout', tx_id=tx_tid, timeout=timeout)
                    value = failure.Failure(TimeoutError(timeout, "Deferred"))
            else:
                # Search pending queue. This may be a cancel coming in from the original
                # task that requested the Tx.  If found, remove
                # from pending queue
                for index, request in enumerate(self._pending[index]):
                    req = request.get(OMCI_CC.PENDING_DEFERRED)
                    if req is not None and req.fields[
                            'transaction_id'] == tx_tid:
                        self._pending[index].pop(index)
                        break

        self._send_next_request(high_priority)
        return value
Ejemplo n.º 9
0
    def _request_timeout(self, tx_tid, high_priority):
        """
        Tx Request timed out.  Resend immediately if there retries is non-zero.  A
        separate deferred (dc) is used on each actual Tx which is not the deferred
        (d) that is returned to the caller of the 'send()' method.

        If the timeout if the transmitted frame was zero, this is just cleanup of
        that transmit request and not necessarily a transmit timeout

        :param tx_tid: (int) TID of frame
        :param high_priority: (bool) True if high-priority queue
        """
        self.log.debug("_request_timeout", tx_tid=tx_tid)
        index = self._get_priority_index(high_priority)

        if self._tx_request[index] is not None:
            # (0: timestamp, 1: defer, 2: frame, 3: timeout, 4: retry, 5: delayedCall)
            ts, d, frame, timeout, retry, _dc = self._tx_request[index]

            if frame.fields.get('transaction_id', 0) == tx_tid:
                self._tx_request[index] = None

                if timeout > 0:
                    self._rx_timeouts += 1

                    if retry > 0:
                        # Push on front of TX pending queue so that it transmits next with the
                        # original TID
                        self._queue_frame(d,
                                          frame,
                                          timeout,
                                          retry - 1,
                                          high_priority,
                                          front=True)

                    elif not d.called:
                        d.errback(
                            failure.Failure(
                                TimeoutError(
                                    timeout,
                                    "Send OMCI TID -{}".format(tx_tid))))
            else:
                self.log.warn('timeout-but-not-the-tx-frame'
                              )  # Statement mainly for debugging

        self._send_next_request(high_priority)
Ejemplo n.º 10
0
 def failure(self, error):
     if error and hasattr(error, "value"):
         if issubclass(type(error.value), ConnectError):
             log_msg("Bank appears to be down?")
             error = None
         elif issubclass(type(error.value), TimeoutError):
             log_msg("Payment was dropped, trying again...", 4, "par")
             error = None
     if error:
         log_ex(error, "Bank payment message failed!")
     #check if the global timeout is up yet:
     if time.time() < self.doneTime:
         #and if not, send try sending again
         self.proxy_message()
     #otherwise, trigger the errback
     else:
         self.finishedDeferred.errback(TimeoutError())
Ejemplo n.º 11
0
    def _request_failure(self, value, tx_tid):
        """
        Handle a transmit failure and/or Rx timeout

        :param value: (Failure) Twisted failure
        :param tx_tid: (int) Associated Tx TID
        """
        if tx_tid in self._requests:
            (_, _, _, timeout) = self._requests.pop(tx_tid)
        else:
            timeout = 0

        if isinstance(value, failure.Failure):
            value.trap(CancelledError)
            self._rx_timeouts += 1
            self._consecutive_errors += 1
            self.log.info('timeout', tx_id=tx_tid, timeout=timeout)
            value = failure.Failure(TimeoutError(timeout, "Deferred"))

        return value
Ejemplo n.º 12
0
    def _request_failure(self, value, tx_tid):
        """
        Handle a transmit failure and/or Rx timeout

        :param value: (Failure) Twisted failure
        :param tx_tid: (int) Associated Tx TID
        """
        if tx_tid in self._requests:
            (_, _, _, timeout, retry, dc) = self._requests.pop(tx_tid)
            if dc is not None and not dc.called and not dc.cancelled:
                dc.cancel()

        if isinstance(value, failure.Failure):
            value.trap(CancelledError)
            self._rx_timeouts += 1
            self._consecutive_errors += 1

            if self._consecutive_errors == 1:
                reactor.callLater(0, self._publish_connectivity_event, False)

            self.log.info('timeout', tx_id=tx_tid, timeout=timeout)
            value = failure.Failure(TimeoutError(timeout, "Deferred"))

        return value
Ejemplo n.º 13
0
 def _ack_timed_out(tm, cache_request):
     lg.out(_DebugLevel, "propagate.PingContact._ack_timed_out")
     if not cache_request.called:
         cache_request.cancel()
     ping_result.errback(
         TimeoutError('response was not received within %d seconds' % tm))
Ejemplo n.º 14
0
 def __init__(self, id):
     TimeoutError.__init__(self)
     self.id = id
Ejemplo n.º 15
0
 def to():
     if not already_fired[0]:
         already_fired[0] = True
         wrapper_d.errback(
             TimeoutError("More than %i seconds elapsed" % timeout))
Ejemplo n.º 16
0
 def __init__(self, id):
     TimeoutError.__init__(self)
     self.id = id
Ejemplo n.º 17
0
 def timed_out(self):
     if not self.done:
         self.done = True
         self.listener.stopListening()
         self.finishedDeferred.errback(TimeoutError())
Ejemplo n.º 18
0
 def _schedule_timeout(self, result=None):
     Scheduler.schedule_once(self.timeout, self.failure, TimeoutError())
Ejemplo n.º 19
0
 def _response_timed_out(pkt_out):
     lg.out(_DebugLevel,
            "propagate.PingContact._response_timed_out : %s" % pkt_out)
     if not ping_result.called:
         ping_result.errback(TimeoutError('remote user did not responded'))
     return None
Ejemplo n.º 20
0
 def got_timeout(self, e):
     for u in self.users:
         u.errback(TimeoutError())
     self.users = []
     self.stop_tasks()
Ejemplo n.º 21
0
 def timeoutConnection(self):
     """
     Close the connection in case of timeout.
     """
     self._cancelCommands(TimeoutError("Connection timeout"))
     self.transport.loseConnection()
Ejemplo n.º 22
0
 def testTimeout(self):
     LoopingCall(work, self, duration=0.1).start(2)
     with ShouldRaise(TimeoutError(0.02, 'Deferred')):
         yield waitForThreads(timeout=0.02)
     cancelDelayedCalls()
Ejemplo n.º 23
0
def _cancelledToTimedOutError(value, timeout):
    if isinstance(value, failure.Failure):
        value.trap(CancelledError)
        raise TimeoutError(timeout, "Deferred")
    return value