mirror of
https://github.com/apache/superset.git
synced 2026-04-18 23:55:00 +00:00
feat(GAQ): Add Redis Sentinel Support for Global Async Queries (#29912)
Co-authored-by: Sivarajan Narayanan <narayanan_sivarajan@apple.com>
This commit is contained in:
@@ -17,15 +17,20 @@
|
||||
from unittest import mock
|
||||
from unittest.mock import ANY, Mock
|
||||
|
||||
import redis
|
||||
from flask import g
|
||||
from jwt import encode
|
||||
from pytest import fixture, raises
|
||||
from pytest import fixture, mark, raises
|
||||
|
||||
from superset import security_manager
|
||||
from superset.async_events.async_query_manager import (
|
||||
AsyncQueryManager,
|
||||
AsyncQueryTokenException,
|
||||
)
|
||||
from superset.async_events.cache_backend import (
|
||||
RedisCacheBackend,
|
||||
RedisSentinelCacheBackend,
|
||||
)
|
||||
|
||||
JWT_TOKEN_SECRET = "some_secret"
|
||||
JWT_TOKEN_COOKIE_NAME = "superset_async_jwt"
|
||||
@@ -36,7 +41,6 @@ def async_query_manager():
|
||||
query_manager = AsyncQueryManager()
|
||||
query_manager._jwt_secret = JWT_TOKEN_SECRET
|
||||
query_manager._jwt_cookie_name = JWT_TOKEN_COOKIE_NAME
|
||||
|
||||
return query_manager
|
||||
|
||||
|
||||
@@ -75,12 +79,24 @@ def test_parse_channel_id_from_request_bad_jwt(async_query_manager):
|
||||
async_query_manager.parse_channel_id_from_request(request)
|
||||
|
||||
|
||||
@mark.parametrize(
|
||||
"cache_type, cache_backend",
|
||||
[
|
||||
("RedisCacheBackend", mock.Mock(spec=RedisCacheBackend)),
|
||||
("RedisSentinelCacheBackend", mock.Mock(spec=RedisSentinelCacheBackend)),
|
||||
("redis.Redis", mock.Mock(spec=redis.Redis)),
|
||||
],
|
||||
)
|
||||
@mock.patch("superset.is_feature_enabled")
|
||||
def test_submit_chart_data_job_as_guest_user(
|
||||
is_feature_enabled_mock, async_query_manager
|
||||
is_feature_enabled_mock, async_query_manager, cache_type, cache_backend
|
||||
):
|
||||
is_feature_enabled_mock.return_value = True
|
||||
set_current_as_guest_user()
|
||||
|
||||
# Mock the get_cache_backend method to return the current cache backend
|
||||
async_query_manager.get_cache_backend = mock.Mock(return_value=cache_backend)
|
||||
|
||||
job_mock = Mock()
|
||||
async_query_manager._load_chart_data_into_cache_job = job_mock
|
||||
job_meta = async_query_manager.submit_chart_data_job(
|
||||
@@ -105,14 +121,27 @@ def test_submit_chart_data_job_as_guest_user(
|
||||
)
|
||||
|
||||
assert "guest_token" not in job_meta
|
||||
job_mock.reset_mock() # Reset the mock for the next iteration
|
||||
|
||||
|
||||
@mark.parametrize(
|
||||
"cache_type, cache_backend",
|
||||
[
|
||||
("RedisCacheBackend", mock.Mock(spec=RedisCacheBackend)),
|
||||
("RedisSentinelCacheBackend", mock.Mock(spec=RedisSentinelCacheBackend)),
|
||||
("redis.Redis", mock.Mock(spec=redis.Redis)),
|
||||
],
|
||||
)
|
||||
@mock.patch("superset.is_feature_enabled")
|
||||
def test_submit_explore_json_job_as_guest_user(
|
||||
is_feature_enabled_mock, async_query_manager
|
||||
is_feature_enabled_mock, async_query_manager, cache_type, cache_backend
|
||||
):
|
||||
is_feature_enabled_mock.return_value = True
|
||||
set_current_as_guest_user()
|
||||
|
||||
# Mock the get_cache_backend method to return the current cache backend
|
||||
async_query_manager.get_cache_backend = mock.Mock(return_value=cache_backend)
|
||||
|
||||
job_mock = Mock()
|
||||
async_query_manager._load_explore_json_into_cache_job = job_mock
|
||||
job_meta = async_query_manager.submit_explore_json_job(
|
||||
|
||||
Reference in New Issue
Block a user