Beispiel #1
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
    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