Beispiel #1
0
    def test_add_and_idle_and_done_callbacks_synchronous(in_context):
        cache = mock.Mock()
        cache.get.return_value = [b"one", b"two"]

        batch = _cache._GlobalCacheGetBatch(None)
        future1 = batch.add(b"foo")
        future2 = batch.add(b"bar")

        assert set(batch.todo.keys()) == {b"foo", b"bar"}
        assert batch.keys == [b"foo", b"bar"]

        with in_context.new(global_cache=cache).use():
            batch.idle_callback()

        cache.get.assert_called_once_with(batch.todo.keys())
        assert future1.result() == b"one"
        assert future2.result() == b"two"
Beispiel #2
0
    def test_add_and_idle_and_done_callbacks_w_error(in_context):
        error = Exception("spurious error")
        cache = mock.Mock()
        cache.get.return_value = tasklets.Future()
        cache.get.return_value.set_exception(error)

        batch = _cache._GlobalCacheGetBatch(None)
        future1 = batch.add(b"foo")
        future2 = batch.add(b"bar")

        assert set(batch.todo.keys()) == {b"foo", b"bar"}
        assert batch.keys == [b"foo", b"bar"]

        with in_context.new(global_cache=cache).use():
            batch.idle_callback()

        cache.get.assert_called_once_with(batch.todo.keys())
        assert future1.exception() is error
        assert future2.exception() is error
Beispiel #3
0
 def test_full():
     batch = _cache._GlobalCacheGetBatch(None)
     assert batch.full() is False