Exemplo n.º 1
0
    def test_add_and_idle_and_done_callbacks(in_context):
        cache = mock.Mock()

        batch = _cache._GlobalCacheWatchBatch({})
        future1 = batch.add(b"foo")
        future2 = batch.add(b"bar")

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

        cache.watch.assert_called_once_with([b"foo", b"bar"])
        assert future1.result() is None
        assert future2.result() is None
Exemplo n.º 2
0
    def test_add_and_idle_and_done_callbacks(in_context):
        cache = mock.Mock(spec=("watch",))
        cache.watch.return_value = None

        batch = _cache._GlobalCacheWatchBatch({})
        future1 = batch.add(b"foo", b"one")
        future2 = batch.add(b"bar", b"two")

        assert batch.expires is None

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

        cache.watch.assert_called_once_with({b"foo": b"one", b"bar": b"two"})
        assert future1.result() is None
        assert future2.result() is None