Commit 52b9ecae authored by Sascha Herzinger's avatar Sascha Herzinger
Browse files

Fixed a bug that occurred when redis entries are discarded

parent f91bf3a3
......@@ -74,17 +74,21 @@ def get_all_data() -> Tuple[Response, int]:
logger.debug("Received GET request on /data.")
wait = request.args.get('wait') == '1'
data_states = []
existing_data_tasks = []
for task_id in session['data_tasks']:
data_state = get_data_state_for_task_id(task_id, wait)
if data_state is None:
warning = "Data state with task_id '{}' expired. " \
"Discarding...".format(task_id)
logger.warning(warning)
continue
# remove internal information from response
del data_state['file_path']
del data_state['meta']
# add additional information to response
data_states.append(data_state)
existing_data_tasks.append(task_id)
session['data_tasks'] = existing_data_tasks
logger.debug("Data states collected. Sending response.")
return jsonify({'data_states': data_states}), 200
......
......@@ -258,6 +258,23 @@ class TestData:
assert data_state['data_type'] == 'mock'
assert 'task_id' in data_state
def test_discard_expired_states(self, test_client):
data_state = {
'a': 'b',
'file_path': '',
'meta': ''
}
redis.set(name='data:456', value=json.dumps(data_state))
with test_client.session_transaction() as sess:
sess['data_tasks'] = ['123', '456']
rv = test_client.get('/data?wait=1')
body = flask.json.loads(rv.get_data())
assert rv.status_code == 200, body
assert len(body['data_states']) == 1
assert body['data_states'][0]['a'] == 'b'
with test_client.session_transaction() as sess:
sess['data_tasks'] = ['456']
def test_valid_response_if_failing_on_get(self, test_client, faiload):
test_client.post('/data', data=faiload['serialized'])
rv = test_client.get('/data?wait=1')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment