コード例 #1
0
 def test_exception_is_handled_in_all(self, caplog):
     # This just verifies the fix for a bug that caused an error during exception handling in Python 3
     store = RedisFeatureStore(url='redis://bad')
     all = store.all(FEATURES, lambda x: x)
     assert all is None
     loglines = get_log_lines(caplog)
     assert len(loglines) == 2
     message = loglines[1].message
     assert message.startswith(
         "RedisFeatureStore: Could not retrieve 'features' from Redis")
     assert "connecting to bad:6379" in message
コード例 #2
0
 def test_exception_is_handled_in_get(self, caplog):
     # This just verifies the fix for a bug that caused an error during exception handling in Python 3
     store = RedisFeatureStore(url='redis://bad')
     feature = store.get(FEATURES, 'flagkey')
     assert feature is None
     loglines = get_log_lines(caplog)
     assert len(loglines) == 2
     message = loglines[1].message
     assert message.startswith(
         "RedisFeatureStore: Could not retrieve key flagkey from 'features' with error:"
     )
     assert "connecting to bad:6379" in message
コード例 #3
0
    def test_upsert_race_condition_against_external_client_with_lower_version(self, mock_method):
        other_client = redis.StrictRedis(host='localhost', port=6379, db=0)
        store = RedisFeatureStore()
        store.init({ FEATURES: {} })

        other_version = {u'key': u'flagkey', u'version': 2}
        def hook(base_key, key):
            if other_version['version'] <= 4:
                other_client.hset(base_key, key, json.dumps(other_version))
                other_version['version'] = other_version['version'] + 1
        mock_method.side_effect = hook

        feature = { u'key': 'flagkey', u'version': 5 }

        store.upsert(FEATURES, feature)
        result = store.get(FEATURES, 'flagkey', lambda x: x)
        assert result['version'] == 5
コード例 #4
0
 def redis_no_local_cache(self):
     r = redis.StrictRedis(host=self.redis_host, port=self.redis_port, db=0)
     r.delete("launchdarkly:features")
     return RedisFeatureStore(expiration=0)
コード例 #5
0
 def init_store(self, prefix=None):
     self._clear_data()
     return RedisFeatureStore(
         expiration=(30 if self._cache_config.enabled else 0),
         prefix=prefix)