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:
@@ -14,9 +14,15 @@
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from typing import Optional
|
||||
from typing import Any, Optional, Type
|
||||
from unittest import mock
|
||||
|
||||
import redis
|
||||
|
||||
from superset.async_events.cache_backend import (
|
||||
RedisCacheBackend,
|
||||
RedisSentinelCacheBackend,
|
||||
)
|
||||
from superset.extensions import async_query_manager
|
||||
from superset.utils import json
|
||||
from tests.integration_tests.base_tests import SupersetTestCase
|
||||
@@ -32,12 +38,21 @@ class TestAsyncEventApi(SupersetTestCase):
|
||||
uri = f"{base_uri}?last_id={last_id}" if last_id else base_uri
|
||||
return self.client.get(uri)
|
||||
|
||||
@mock.patch("uuid.uuid4", return_value=UUID)
|
||||
def test_events(self, mock_uuid4):
|
||||
def run_test_with_cache_backend(self, cache_backend_cls: Type[Any], test_func):
|
||||
app._got_first_request = False
|
||||
async_query_manager.init_app(app)
|
||||
|
||||
# Create a mock cache backend instance
|
||||
mock_cache = mock.Mock(spec=cache_backend_cls)
|
||||
|
||||
# Set the mock cache instance
|
||||
async_query_manager._cache = mock_cache
|
||||
|
||||
self.login(ADMIN_USERNAME)
|
||||
with mock.patch.object(async_query_manager._redis, "xrange") as mock_xrange:
|
||||
test_func(mock_cache)
|
||||
|
||||
def _test_events_logic(self, mock_cache):
|
||||
with mock.patch.object(mock_cache, "xrange") as mock_xrange:
|
||||
rv = self.fetch_events()
|
||||
response = json.loads(rv.data.decode("utf-8"))
|
||||
|
||||
@@ -46,12 +61,8 @@ class TestAsyncEventApi(SupersetTestCase):
|
||||
mock_xrange.assert_called_with(channel_id, "-", "+", 100)
|
||||
self.assertEqual(response, {"result": []})
|
||||
|
||||
@mock.patch("uuid.uuid4", return_value=UUID)
|
||||
def test_events_last_id(self, mock_uuid4):
|
||||
app._got_first_request = False
|
||||
async_query_manager.init_app(app)
|
||||
self.login(ADMIN_USERNAME)
|
||||
with mock.patch.object(async_query_manager._redis, "xrange") as mock_xrange:
|
||||
def _test_events_last_id_logic(self, mock_cache):
|
||||
with mock.patch.object(mock_cache, "xrange") as mock_xrange:
|
||||
rv = self.fetch_events("1607471525180-0")
|
||||
response = json.loads(rv.data.decode("utf-8"))
|
||||
|
||||
@@ -60,12 +71,8 @@ class TestAsyncEventApi(SupersetTestCase):
|
||||
mock_xrange.assert_called_with(channel_id, "1607471525180-1", "+", 100)
|
||||
self.assertEqual(response, {"result": []})
|
||||
|
||||
@mock.patch("uuid.uuid4", return_value=UUID)
|
||||
def test_events_results(self, mock_uuid4):
|
||||
app._got_first_request = False
|
||||
async_query_manager.init_app(app)
|
||||
self.login(ADMIN_USERNAME)
|
||||
with mock.patch.object(async_query_manager._redis, "xrange") as mock_xrange:
|
||||
def _test_events_results_logic(self, mock_cache):
|
||||
with mock.patch.object(mock_cache, "xrange") as mock_xrange:
|
||||
mock_xrange.return_value = [
|
||||
(
|
||||
"1607477697866-0",
|
||||
@@ -110,6 +117,20 @@ class TestAsyncEventApi(SupersetTestCase):
|
||||
}
|
||||
self.assertEqual(response, expected)
|
||||
|
||||
@mock.patch("uuid.uuid4", return_value=UUID)
|
||||
def test_events_redis_cache_backend(self, mock_uuid4):
|
||||
self.run_test_with_cache_backend(RedisCacheBackend, self._test_events_logic)
|
||||
|
||||
@mock.patch("uuid.uuid4", return_value=UUID)
|
||||
def test_events_redis_sentinel_cache_backend(self, mock_uuid4):
|
||||
self.run_test_with_cache_backend(
|
||||
RedisSentinelCacheBackend, self._test_events_logic
|
||||
)
|
||||
|
||||
@mock.patch("uuid.uuid4", return_value=UUID)
|
||||
def test_events_redis(self, mock_uuid4):
|
||||
self.run_test_with_cache_backend(redis.Redis, self._test_events_logic)
|
||||
|
||||
def test_events_no_login(self):
|
||||
app._got_first_request = False
|
||||
async_query_manager.init_app(app)
|
||||
|
||||
Reference in New Issue
Block a user