superset-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-superset] bkyryliuk commented on a change in pull request #10761: feat: implement cache invalidation api
Date Thu, 10 Sep 2020 23:48:12 GMT

bkyryliuk commented on a change in pull request #10761:
URL: https://github.com/apache/incubator-superset/pull/10761#discussion_r486693694



##########
File path: tests/cachekeys/api_tests.py
##########
@@ -0,0 +1,131 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# isort:skip_file
+"""Unit tests for Superset"""
+from tests.test_app import app  # noqa
+
+from superset.extensions import cache_manager, db
+from superset.models.cache import CacheKey
+from tests.base_tests import (
+    SupersetTestCase,
+    post_assert_metric,
+    test_client,
+    logged_in_admin,
+)  # noqa
+
+
+def test_invalidate_cache(logged_in_admin):
+    rv = post_assert_metric(
+        test_client,
+        "api/v1/cache/invalidate",
+        {"datasource_uids": ["3__table"]},
+        "invalidate",
+    )
+    assert rv.status_code == 201
+
+
+def test_invalidate_existing_cache(logged_in_admin):
+    db.session.add(CacheKey(cache_key="cache_key", datasource_uid="3__table"))
+    db.session.commit()
+    cache_manager.cache.set("cache_key", "value")
+
+    rv = post_assert_metric(
+        test_client,
+        "api/v1/cache/invalidate",
+        {"datasource_uids": ["3__table"]},
+        "invalidate",
+    )
+
+    assert rv.status_code == 201
+    assert cache_manager.cache.get("cache_key") == None
+    assert (
+        not db.session.query(CacheKey).filter(CacheKey.cache_key == "cache_key").first()
+    )
+
+
+def test_invalidate_existing_caches(logged_in_admin):
+    bn = SupersetTestCase.get_birth_names_dataset()
+
+    db.session.add(CacheKey(cache_key="cache_key1", datasource_uid="3__druid"))
+    db.session.add(CacheKey(cache_key="cache_key2", datasource_uid="3__druid"))
+    db.session.add(CacheKey(cache_key="cache_key4", datasource_uid=f"{bn.id}__table"))
+    db.session.add(CacheKey(cache_key="cache_keyX", datasource_uid="X__table"))
+    db.session.commit()
+
+    cache_manager.cache.set("cache_key1", "value")
+    cache_manager.cache.set("cache_key2", "value")
+    cache_manager.cache.set("cache_key4", "value")
+    cache_manager.cache.set("cache_keyX", "value")
+
+    rv = post_assert_metric(
+        test_client,
+        "api/v1/cache/invalidate",
+        {
+            "datasource_uids": ["3__druid", "4__druid"],

Review comment:
       done, it caught the bug by the way :) thanks !




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Mime
View raw message