def test_redis_resync(flowmachine_connect): """ Test that redis states can be resynced to the flowdb cache. """ stored_query = daily_location("2016-01-01").store().result() assert ( QueryStateMachine( get_redis(), stored_query.query_id, get_db().conn_id ).current_query_state == QueryState.COMPLETED ) assert stored_query.is_stored get_redis().flushdb() assert stored_query.is_stored assert ( QueryStateMachine( get_redis(), stored_query.query_id, get_db().conn_id ).current_query_state == QueryState.KNOWN ) resync_redis_with_cache(get_db(), get_redis()) assert ( QueryStateMachine( get_redis(), stored_query.query_id, get_db().conn_id ).current_query_state == QueryState.COMPLETED )
def test_redis_resync_runtimeerror(flowmachine_connect, dummy_redis): """ Test that a runtime error is raised if redis is being updated from multiple places when trying to resync. """ stored_query = daily_location("2016-01-01").store().result() assert (QueryStateMachine( Table.redis, stored_query.query_id).current_query_state == QueryState.COMPLETED) dummy_redis.allow_flush = False with pytest.raises(RuntimeError): resync_redis_with_cache(flowmachine_connect, dummy_redis)