Пример #1
0
 def test_backend_not_called_if_no_state_ttl(self, stub_broker, do_work,
                                             state_ttl):
     backend = Mock()
     stub_broker.add_middleware(
         MessageState(backend=backend, state_ttl=state_ttl))
     do_work.send()
     assert backend.set_state.call_count == 0
Пример #2
0
    def test_maximum_size(self, max_size, expected, stub_broker, state_backend,
                          do_work):
        @remoulade.actor
        def do_work(x):
            return x

        stub_broker.add_middleware(
            MessageState(backend=state_backend, max_size=max_size))
        stub_broker.declare_actor(do_work)
        msg = do_work.send(5)
        args = state_backend.get_state(msg.message_id).args
        # if the max_size = 0, then should not storage nothing
        assert args == expected
Пример #3
0
    def test_expiration_data_backend(self, ttl, result_type, stub_broker,
                                     state_backend):
        @remoulade.actor
        def wait():
            time.sleep(0.3)

        stub_broker.add_middleware(
            MessageState(backend=state_backend, state_ttl=ttl))
        stub_broker.declare_actor(wait)
        msg = wait.send()
        time.sleep(2)
        data = state_backend.get_state(msg.message_id)
        # if the ttl is  greater than the expiration, the data should be None
        assert type(data) == result_type
Пример #4
0
    def test_expiration_data_backend(self, ttl, result_type, stub_broker, state_backend):

        if type(state_backend) == PostgresBackend:
            pytest.skip("Skipping this test as there is no expiration on PostgresBackend")

        @remoulade.actor
        def wait():
            pass

        stub_broker.add_middleware(MessageState(backend=state_backend, state_ttl=ttl))
        stub_broker.declare_actor(wait)
        msg = wait.send()
        time.sleep(2)
        data = state_backend.get_state(msg.message_id)
        # if the ttl is  greater than the expiration, the data should be None
        assert type(data) == result_type
Пример #5
0
    def test_maximum_size_args(self, max_size, stub_broker, state_backend, do_work):
        @remoulade.actor
        def do_work(x):
            return x

        state_backend.max_size = max_size
        stub_broker.add_middleware(MessageState(backend=state_backend))
        stub_broker.declare_actor(do_work)
        long_string = "".join("a" for _ in range(256))
        msg = do_work.send(long_string)
        args = state_backend.get_state(msg.message_id).args
        # if the max_size == 0, then should not storage nothing

        if max_size > 200:
            assert list(args) == [long_string]
        else:
            assert args is None