예제 #1
0
    def test_redis_down(self):
        metric_reporter = pretend.stub(
            increment=pretend.call_recorder(lambda *args: None)
        )
        down_redis = pretend.stub(
            hget=pretend.raiser(redis.exceptions.RedisError),
            pipeline=pretend.raiser(redis.exceptions.RedisError),
            scan_iter=pretend.raiser(redis.exceptions.RedisError),
        )
        redis_lru = RedisLru(down_redis, metric_reporter=metric_reporter)

        expected = func_test(0, 1, kwarg0=2, kwarg1=3)

        assert expected == redis_lru.fetch(
            func_test, [0, 1], {"kwarg0": 2, "kwarg1": 3}, None, "test", None
        )
        assert expected == redis_lru.fetch(
            func_test, [0, 1], {"kwarg0": 2, "kwarg1": 3}, None, "test", None
        )
        with pytest.raises(CacheError):
            redis_lru.purge("test")

        assert metric_reporter.increment.calls == [
            pretend.call("lru.cache.error"),  # Failed get
            pretend.call("lru.cache.miss"),
            pretend.call("lru.cache.error"),  # Failed add
            pretend.call("lru.cache.error"),  # Failed get
            pretend.call("lru.cache.miss"),
            pretend.call("lru.cache.error"),  # Failed add
            pretend.call("lru.cache.error"),  # Failed purge
        ]
예제 #2
0
    def test_redis_lru(self, mockredis):
        redis_lru = RedisLru(mockredis)

        expected = func_test(0, 1, kwarg0=2, kwarg1=3)

        assert expected == redis_lru.fetch(
            func_test, [0, 1], {"kwarg0": 2, "kwarg1": 3}, None, None, None
        )
        assert expected == redis_lru.fetch(
            func_test, [0, 1], {"kwarg0": 2, "kwarg1": 3}, None, None, None
        )
예제 #3
0
    def test_redis_lru(self, fakeredis):
        redis_lru = RedisLru(fakeredis)

        expected = func_test(0, 1, kwarg0=2, kwarg1=3)

        assert expected == redis_lru.fetch(
            func_test, [0, 1], {"kwarg0": 2, "kwarg1": 3}, None, None, None
        )
        assert expected == redis_lru.fetch(
            func_test, [0, 1], {"kwarg0": 2, "kwarg1": 3}, None, None, None
        )
예제 #4
0
    def test_redis_lru(self, fakeredis):
        redis_lru = RedisLru(fakeredis)

        expected = func_test(0, 1, kwarg0=2, kwarg1=3)

        assert expected == redis_lru.fetch(func_test, [0, 1], {
            'kwarg0': 2,
            'kwarg1': 3
        }, None, None, None)
        assert expected == redis_lru.fetch(func_test, [0, 1], {
            'kwarg0': 2,
            'kwarg1': 3
        }, None, None, None)
예제 #5
0
    def test_redis_purge(self, fakeredis):
        metric_reporter = pretend.stub(
            increment=pretend.call_recorder(lambda *args: None))
        redis_lru = RedisLru(fakeredis, metric_reporter=metric_reporter)

        expected = func_test(0, 1, kwarg0=2, kwarg1=3)

        assert expected == redis_lru.fetch(func_test, [0, 1], {
            "kwarg0": 2,
            "kwarg1": 3
        }, None, "test", None)
        assert expected == redis_lru.fetch(func_test, [0, 1], {
            "kwarg0": 2,
            "kwarg1": 3
        }, None, "test", None)
        redis_lru.purge("test")
        assert expected == redis_lru.fetch(func_test, [0, 1], {
            "kwarg0": 2,
            "kwarg1": 3
        }, None, "test", None)
        assert expected == redis_lru.fetch(func_test, [0, 1], {
            "kwarg0": 2,
            "kwarg1": 3
        }, None, "test", None)
        assert metric_reporter.increment.calls == [
            pretend.call("lru.cache.miss"),
            pretend.call("lru.cache.hit"),
            pretend.call("lru.cache.purge"),
            pretend.call("lru.cache.miss"),
            pretend.call("lru.cache.hit"),
        ]
예제 #6
0
    def test_redis_purge(self, fakeredis):
        metric_reporter = pretend.stub(
            increment=pretend.call_recorder(lambda *args: None))
        redis_lru = RedisLru(fakeredis, metric_reporter=metric_reporter)

        expected = func_test(0, 1, kwarg0=2, kwarg1=3)

        assert expected == redis_lru.fetch(func_test, [0, 1], {
            'kwarg0': 2,
            'kwarg1': 3
        }, None, 'test', None)
        assert expected == redis_lru.fetch(func_test, [0, 1], {
            'kwarg0': 2,
            'kwarg1': 3
        }, None, 'test', None)
        redis_lru.purge('test')
        assert expected == redis_lru.fetch(func_test, [0, 1], {
            'kwarg0': 2,
            'kwarg1': 3
        }, None, 'test', None)
        assert expected == redis_lru.fetch(func_test, [0, 1], {
            'kwarg0': 2,
            'kwarg1': 3
        }, None, 'test', None)
        assert metric_reporter.increment.calls == [
            pretend.call('lru.cache.miss'),
            pretend.call('lru.cache.hit'),
            pretend.call('lru.cache.purge'),
            pretend.call('lru.cache.miss'),
            pretend.call('lru.cache.hit'),
        ]
예제 #7
0
    def test_redis_purge(self, fakeredis):
        metric_reporter = pretend.stub(
            increment=pretend.call_recorder(lambda *args: None)
        )
        redis_lru = RedisLru(fakeredis, metric_reporter=metric_reporter)

        expected = func_test(0, 1, kwarg0=2, kwarg1=3)

        assert expected == redis_lru.fetch(
            func_test, [0, 1], {"kwarg0": 2, "kwarg1": 3}, None, "test", None
        )
        assert expected == redis_lru.fetch(
            func_test, [0, 1], {"kwarg0": 2, "kwarg1": 3}, None, "test", None
        )
        redis_lru.purge("test")
        assert expected == redis_lru.fetch(
            func_test, [0, 1], {"kwarg0": 2, "kwarg1": 3}, None, "test", None
        )
        assert expected == redis_lru.fetch(
            func_test, [0, 1], {"kwarg0": 2, "kwarg1": 3}, None, "test", None
        )
        assert metric_reporter.increment.calls == [
            pretend.call("lru.cache.miss"),
            pretend.call("lru.cache.hit"),
            pretend.call("lru.cache.purge"),
            pretend.call("lru.cache.miss"),
            pretend.call("lru.cache.hit"),
        ]
예제 #8
0
    def test_redis_purge(self, fakeredis):
        metric_reporter = pretend.stub(
            increment=pretend.call_recorder(lambda *args: None)
        )
        redis_lru = RedisLru(fakeredis, metric_reporter=metric_reporter)

        expected = func_test(0, 1, kwarg0=2, kwarg1=3)

        assert expected == redis_lru.fetch(
            func_test, [0, 1], {'kwarg0': 2, 'kwarg1': 3}, None, 'test', None
        )
        assert expected == redis_lru.fetch(
            func_test, [0, 1], {'kwarg0': 2, 'kwarg1': 3}, None, 'test', None
        )
        redis_lru.purge('test')
        assert expected == redis_lru.fetch(
            func_test, [0, 1], {'kwarg0': 2, 'kwarg1': 3}, None, 'test', None
        )
        assert expected == redis_lru.fetch(
            func_test, [0, 1], {'kwarg0': 2, 'kwarg1': 3}, None, 'test', None
        )
        assert metric_reporter.increment.calls == [
            pretend.call('lru.cache.miss'),
            pretend.call('lru.cache.hit'),
            pretend.call('lru.cache.purge'),
            pretend.call('lru.cache.miss'),
            pretend.call('lru.cache.hit'),
        ]
예제 #9
0
    def test_redis_down(self):
        metric_reporter = pretend.stub(
            increment=pretend.call_recorder(lambda *args: None))
        down_redis = pretend.stub(
            hget=pretend.raiser(redis.exceptions.RedisError),
            pipeline=pretend.raiser(redis.exceptions.RedisError),
            scan_iter=pretend.raiser(redis.exceptions.RedisError),
        )
        redis_lru = RedisLru(down_redis, metric_reporter=metric_reporter)

        expected = func_test(0, 1, kwarg0=2, kwarg1=3)

        assert expected == redis_lru.fetch(func_test, [0, 1], {
            "kwarg0": 2,
            "kwarg1": 3
        }, None, "test", None)
        assert expected == redis_lru.fetch(func_test, [0, 1], {
            "kwarg0": 2,
            "kwarg1": 3
        }, None, "test", None)
        with pytest.raises(CacheError):
            redis_lru.purge("test")

        assert metric_reporter.increment.calls == [
            pretend.call("lru.cache.error"),  # Failed get
            pretend.call("lru.cache.miss"),
            pretend.call("lru.cache.error"),  # Failed add
            pretend.call("lru.cache.error"),  # Failed get
            pretend.call("lru.cache.miss"),
            pretend.call("lru.cache.error"),  # Failed add
            pretend.call("lru.cache.error"),  # Failed purge
        ]