Ejemplo n.º 1
0
def call_geovelo_func_with_circuit_breaker_error_test():
    instance = MagicMock()
    geovelo = Geovelo(instance=instance, service_url='http://bob.com')
    geovelo.breaker = MagicMock()
    geovelo.breaker.call = MagicMock(
        side_effect=pybreaker.CircuitBreakerError())
    assert geovelo._call_geovelo(geovelo.service_url) == None
Ejemplo n.º 2
0
def call_geovelo_func_with_circuit_breaker_error_test():
    instance = MagicMock()
    geovelo = Geovelo(instance=instance, service_url='http://bob.com')
    geovelo.breaker = MagicMock()
    geovelo.breaker.call = MagicMock(side_effect=pybreaker.CircuitBreakerError())
    with pytest.raises(jormungandr.exceptions.GeoveloTechnicalError):
        geovelo._call_geovelo(geovelo.service_url)
Ejemplo n.º 3
0
    async def call_async(self, f, *args, **kwargs):
        """
        Run the circuit breaker with native python async.
        """
        def raise_err_callback(err):
            def f():
                raise err

            return f

        # Check that the circuit breaker is open
        with self._lock:
            state = self.state

            if isinstance(state, pybreaker.CircuitOpenState):
                timeout = timedelta(seconds=state._breaker.reset_timeout)
                opened_at = state._breaker._state_storage.opened_at

                if opened_at and datetime.utcnow() < opened_at + timeout:
                    raise pybreaker.CircuitBreakerError(
                        "Timeout not elapsed yet")

                state._breaker.half_open()

            # Build a synchronous `callback` function that simulates the return
            # behaviour of `f`.
            try:
                res = await f(*args, **kwargs)
                callback = lambda: res
            except Exception as err:
                callback = raise_err_callback(err)

            return self.call(callback)
Ejemplo n.º 4
0
def call_valhalla_func_with_circuit_breaker_error_test():
    instance = MagicMock()
    valhalla = Valhalla(instance=instance,
                        service_url='http://bob.com',
                        costing_options={'bib': 'bom'})
    valhalla.breaker = MagicMock()
    valhalla.breaker.call = MagicMock(side_effect=pybreaker.CircuitBreakerError())
    assert valhalla._call_valhalla(valhalla.service_url) == None