|
8 | 8 | from ldclient.versioned_data_kind import FEATURES |
9 | 9 |
|
10 | 10 |
|
| 11 | +def get_log_lines(caplog): |
| 12 | + loglines = caplog.records |
| 13 | + if callable(loglines): |
| 14 | + # records() is a function in older versions of the caplog plugin |
| 15 | + loglines = loglines() |
| 16 | + return loglines |
| 17 | + |
| 18 | + |
11 | 19 | class TestFeatureStore: |
12 | 20 | redis_host = 'localhost' |
13 | 21 | redis_port = 6379 |
@@ -162,3 +170,25 @@ def hook(base_key, key): |
162 | 170 | store.upsert(FEATURES, feature) |
163 | 171 | result = store.get(FEATURES, 'flagkey', lambda x: x) |
164 | 172 | assert result['version'] == 5 |
| 173 | + |
| 174 | + def test_exception_is_handled_in_get(self, caplog): |
| 175 | + # This just verifies the fix for a bug that caused an error during exception handling in Python 3 |
| 176 | + store = RedisFeatureStore(url='redis://bad') |
| 177 | + feature = store.get(FEATURES, 'flagkey') |
| 178 | + assert feature is None |
| 179 | + loglines = get_log_lines(caplog) |
| 180 | + assert len(loglines) == 2 |
| 181 | + message = loglines[1].message |
| 182 | + assert message.startswith("RedisFeatureStore: Could not retrieve key flagkey from 'features' with error:") |
| 183 | + assert "connecting to bad:6379" in message |
| 184 | + |
| 185 | + def test_exception_is_handled_in_all(self, caplog): |
| 186 | + # This just verifies the fix for a bug that caused an error during exception handling in Python 3 |
| 187 | + store = RedisFeatureStore(url='redis://bad') |
| 188 | + all = store.all(FEATURES, lambda x: x) |
| 189 | + assert all is None |
| 190 | + loglines = get_log_lines(caplog) |
| 191 | + assert len(loglines) == 2 |
| 192 | + message = loglines[1].message |
| 193 | + assert message.startswith("RedisFeatureStore: Could not retrieve 'features' from Redis") |
| 194 | + assert "connecting to bad:6379" in message |
0 commit comments