def test_add_done_callback_already_done():
     future = tasklets.Future()
     future.set_result(None)
     call = _remote.RemoteCall(future, "testing")
     callback = mock.Mock(spec=())
     call.add_done_callback(callback)
     callback.assert_called_once_with(call)
 def test_cancel():
     future = tasklets.Future()
     call = _remote.RemoteCall(future, "testing")
     call.cancel()
     assert future.cancelled()
     with pytest.raises(exceptions.Cancelled):
         call.result()
Ejemplo n.º 3
0
    def rpc_call():
        call = method.future(request, timeout=timeout)
        rpc = _remote.RemoteCall(call, "{}({})".format(rpc_name, request))
        log.debug(rpc)
        log.debug("timeout={}".format(timeout))

        result = yield rpc
        return result
Ejemplo n.º 4
0
    def rpc_call():
        context = context_module.get_toplevel_context()

        call = method.future(request, timeout=timeout)
        rpc = _remote.RemoteCall(call, "{}({})".format(rpc_name, request))
        log.debug(rpc)
        log.debug("timeout={}".format(timeout))

        try:
            result = yield rpc
        except Exception as error:
            if isinstance(error, grpc.Call):
                error = core_exceptions.from_grpc_error(error)
            raise error
        finally:
            context.rpc_time += rpc.elapsed_time

        raise tasklets.Return(result)
Ejemplo n.º 5
0
    def rpc_call():
        context = context_module.get_toplevel_context()

        call = method.future(request, timeout=timeout)
        rpc = _remote.RemoteCall(call, rpc_name)
        utils.logging_debug(log, rpc)
        utils.logging_debug(log, "timeout={}", timeout)

        try:
            result = yield rpc
        except Exception as error:
            if isinstance(error, grpc.Call):
                error = core_exceptions.from_grpc_error(error)
            raise error
        finally:
            context.rpc_time += rpc.elapsed_time

        raise tasklets.Return(result)
Ejemplo n.º 6
0
    def test_cancel():
        # Integration test. Actually test that a cancel propagates properly.
        rpc = tasklets.Future("Fake RPC")
        wrapped_rpc = _remote.RemoteCall(rpc, "Wrapped Fake RPC")

        @tasklets.tasklet
        def inner_tasklet():
            yield wrapped_rpc

        @tasklets.tasklet
        def outer_tasklet():
            yield inner_tasklet()

        future = outer_tasklet()
        assert not future.cancelled()
        future.cancel()
        assert rpc.cancelled()

        with pytest.raises(exceptions.Cancelled):
            future.result()

        assert future.cancelled()
 def test_result():
     future = tasklets.Future()
     future.set_result("positive")
     call = _remote.RemoteCall(future, "testing")
     assert call.result() == "positive"
 def test_exception_FutureCancelledError():
     error = grpc.FutureCancelledError()
     future = tasklets.Future()
     future.exception = mock.Mock(side_effect=error)
     call = _remote.RemoteCall(future, "testing")
     assert isinstance(call.exception(), exceptions.Cancelled)
 def test_exception():
     error = Exception("Spurious error")
     future = tasklets.Future()
     future.set_exception(error)
     call = _remote.RemoteCall(future, "testing")
     assert call.exception() is error
Ejemplo n.º 10
0
 def test_repr():
     future = tasklets.Future()
     call = _remote.RemoteCall(future, "a remote call")
     assert repr(call) == "a remote call"
Ejemplo n.º 11
0
 def test_constructor():
     future = tasklets.Future()
     call = _remote.RemoteCall(future, "info")
     assert call.future is future
     assert call.info == "info"
Ejemplo n.º 12
0
 def test_repr():
     call = _remote.RemoteCall(None, "a remote call")
     assert repr(call) == "a remote call"
Ejemplo n.º 13
0
 def test_constructor():
     call = _remote.RemoteCall("future", "info")
     assert call.future == "future"
     assert call.info == "info"
Ejemplo n.º 14
0
 def rpc_call():
     rpc = _remote.RemoteCall(method.future(request),
                              "{}({})".format(rpc_name, request))
     log.debug(rpc)
     result = yield rpc
     return result