Repository: CSCfi/rems
Pull request #2995 (2022-09-02 13:39:15)

Update rems.db.testing/caches-fixture
- rename `rems.db.testing/caches-fixture` to `rems.db.testing/reset-caches-fixture`, update to contain more cache resets across db namespaces, add `reset-caches-fixture` to `rems.db.test-transactions`

# Checklist for author

Remove items that aren't applicable, check items that are done.

## Testing
- [x] Valuable features are integration / browser / acceptance tested automatically



Patch:
diff --git a/src/clj/rems/db/applications.clj b/src/clj/rems/db/applications.clj
index 445407859..2080ae5e4 100644
--- a/src/clj/rems/db/applications.clj
+++ b/src/clj/rems/db/applications.clj
@@ -294,3 +294,7 @@
 (defn delete-application-and-reload-cache! [app-id]
   (delete-application! app-id)
   (reload-cache!))
+
+(defn reset-cache! []
+  (events-cache/empty! all-applications-cache))
+


Test patch:
diff --git a/test/clj/rems/api/services/test_catalogue.clj b/test/clj/rems/api/services/test_catalogue.clj
index 2d62e8cec..b630424a2 100644
--- a/test/clj/rems/api/services/test_catalogue.clj
+++ b/test/clj/rems/api/services/test_catalogue.clj
@@ -8,14 +8,14 @@
             [rems.db.core :as db]
             [rems.db.category :as category]
             [rems.db.test-data-helpers :as test-helpers]
-            [rems.db.testing :refer [caches-fixture rollback-db-fixture test-db-fixture]]
+            [rems.db.testing :refer [reset-caches-fixture rollback-db-fixture test-db-fixture]]
             [rems.testing-util :refer [with-user]])
   (:import org.joda.time.DateTime))
 
 (use-fixtures
   :once
   test-db-fixture
-  caches-fixture)
+  reset-caches-fixture)
 
 (use-fixtures :each rollback-db-fixture)
 
diff --git a/test/clj/rems/api/services/test_dependencies.clj b/test/clj/rems/api/services/test_dependencies.clj
index 1f2a00474..628037d57 100644
--- a/test/clj/rems/api/services/test_dependencies.clj
+++ b/test/clj/rems/api/services/test_dependencies.clj
@@ -3,13 +3,13 @@
             [rems.api.services.dependencies :as dependencies]
             [rems.db.core :as db]
             [rems.db.test-data-helpers :as test-helpers]
-            [rems.db.testing :refer [caches-fixture test-db-fixture rollback-db-fixture]]))
+            [rems.db.testing :refer [reset-caches-fixture test-db-fixture rollback-db-fixture]]))
 
 (use-fixtures :once test-db-fixture)
 (use-fixtures
   :each
   rollback-db-fixture
-  caches-fixture)
+  reset-caches-fixture)
 
 (deftest test-dependencies
   (let [shared-license (test-helpers/create-license! {})
diff --git a/test/clj/rems/api/services/test_invitation.clj b/test/clj/rems/api/services/test_invitation.clj
index 904540fc3..70fc646ca 100644
--- a/test/clj/rems/api/services/test_invitation.clj
+++ b/test/clj/rems/api/services/test_invitation.clj
@@ -2,7 +2,7 @@
   (:require [clojure.test :refer :all]
             [rems.api.services.invitation :as invitation]
             [rems.db.test-data-helpers :as test-helpers]
-            [rems.db.testing :refer [caches-fixture rollback-db-fixture test-db-fixture]]
+            [rems.db.testing :refer [reset-caches-fixture rollback-db-fixture test-db-fixture]]
             [rems.email.core :as email]
             [rems.testing-util :refer [fixed-time-fixture with-user]])
   (:import [org.joda.time DateTime DateTimeUtils DateTimeZone]))
@@ -13,7 +13,7 @@
 (use-fixtures
   :once
   test-db-fixture
-  caches-fixture
+  reset-caches-fixture
   (fixed-time-fixture invitation-time))
 
 (use-fixtures :each rollback-db-fixture)
diff --git a/test/clj/rems/api/services/test_workflow.clj b/test/clj/rems/api/services/test_workflow.clj
index 68c13e806..d2889c6b4 100644
--- a/test/clj/rems/api/services/test_workflow.clj
+++ b/test/clj/rems/api/services/test_workflow.clj
@@ -2,13 +2,13 @@
   (:require [clojure.test :refer :all]
             [rems.api.services.workflow :as workflow]
             [rems.db.test-data-helpers :as test-helpers]
-            [rems.db.testing :refer [caches-fixture rollback-db-fixture test-db-fixture]]
+            [rems.db.testing :refer [reset-caches-fixture rollback-db-fixture test-db-fixture]]
             [rems.testing-util :refer [with-user]]))
 
 (use-fixtures
   :once
   test-db-fixture
-  caches-fixture)
+  reset-caches-fixture)
 
 (use-fixtures :each rollback-db-fixture)
 
diff --git a/test/clj/rems/api/testing.clj b/test/clj/rems/api/testing.clj
index 0432493a1..fc5b11ea1 100644
--- a/test/clj/rems/api/testing.clj
+++ b/test/clj/rems/api/testing.clj
@@ -5,7 +5,7 @@
             [clojure.test :refer :all]
             [mount.core :as mount]
             [muuntaja.core :as muuntaja]
-            [rems.db.testing :refer [reset-db-fixture rollback-db-fixture test-db-fixture caches-fixture search-index-fixture]]
+            [rems.db.testing :refer [reset-db-fixture rollback-db-fixture test-db-fixture reset-caches-fixture search-index-fixture]]
             [rems.handler :refer :all]
             [rems.locales]
             [rems.middleware]
@@ -37,7 +37,7 @@
                   rollback-db-fixture
                   handler-fixture
                   search-index-fixture
-                  caches-fixture]))
+                  reset-caches-fixture]))
 
 (defn authenticate [request api-key user-id]
   (cond-> request
diff --git a/test/clj/rems/db/test_entitlements.clj b/test/clj/rems/db/test_entitlements.clj
index 2c3e3cc8f..42e1aed46 100644
--- a/test/clj/rems/db/test_entitlements.clj
+++ b/test/clj/rems/db/test_entitlements.clj
@@ -6,7 +6,7 @@
             [rems.db.core :as db]
             [rems.db.entitlements :as entitlements]
             [rems.db.test-data-helpers :as test-helpers]
-            [rems.db.testing :refer [caches-fixture test-db-fixture rollback-db-fixture]]
+            [rems.db.testing :refer [reset-caches-fixture test-db-fixture rollback-db-fixture]]
             [rems.json :as json]
             [rems.testing-util :refer [fixed-time-fixture suppress-logging]]
             [stub-http.core :as stub]))
@@ -20,7 +20,7 @@
   (suppress-logging "rems.db.entitlements")
   test-db-fixture
   rollback-db-fixture
-  caches-fixture)
+  reset-caches-fixture)
 
 (def +entitlements+
   [{:resid "res1" :catappid 11 :userid "user1" :start (time/date-time 2001 10 11) :mail "user1@tes.t" :end (time/date-time 2003 10 11)}
diff --git a/test/clj/rems/db/test_transactions.clj b/test/clj/rems/db/test_transactions.clj
index d8a17e88a..23f19f215 100644
--- a/test/clj/rems/db/test_transactions.clj
+++ b/test/clj/rems/db/test_transactions.clj
@@ -5,7 +5,7 @@
             [rems.db.core :as db]
             [rems.db.events :as events]
             [rems.db.test-data-helpers :as test-helpers]
-            [rems.db.testing :refer [test-db-fixture reset-db-fixture]]
+            [rems.db.testing :refer [reset-caches-fixture test-db-fixture reset-db-fixture]]
             [rems.db.users :as users])
   (:import [java.sql SQLException]
            [java.util.concurrent Executors Future TimeUnit ExecutorService]
@@ -14,7 +14,8 @@
 (use-fixtures
   :once
   test-db-fixture
-  reset-db-fixture)
+  reset-db-fixture
+  reset-caches-fixture)
 
 (defn- create-dummy-user []
   (let [user-id "user"]
diff --git a/test/clj/rems/db/testing.clj b/test/clj/rems/db/testing.clj
index deca71f63..04f007450 100644
--- a/test/clj/rems/db/testing.clj
+++ b/test/clj/rems/db/testing.clj
@@ -4,9 +4,11 @@
             [conman.core :as conman]
             [luminus-migrations.core :as migrations]
             [mount.core :as mount]
+            [rems.api.services.dependencies :as dependencies]
             [rems.application.search]
             [rems.config :refer [env]]
-            [rems.db.applications]
+            [rems.db.applications :as applications]
+            [rems.db.catalogue :as catalogue]
             [rems.db.category :as category]
             [rems.db.core :as db]
             [rems.db.test-data :as test-data]
@@ -27,7 +29,7 @@
                          #'rems.locales/translations
                          #'rems.db.core/*db*)
   (db/assert-test-database!)
-  (rems.db.applications/empty-injections-cache!)
+  (applications/empty-injections-cache!)
   (migrations/migrate ["migrate"] {:database-url (:test-database-url env)})
   (f)
   (mount/stop))
@@ -37,12 +39,15 @@
   (mount/start #'rems.application.search/search-index)
   (f))
 
-(defn caches-fixture [f]
+(defn reset-caches-fixture [f]
   (try
-    (mount/start #'rems.db.applications/all-applications-cache)
+    (mount/start #'applications/all-applications-cache)
     (f)
     (finally
+      (applications/reset-cache!)
+      (catalogue/reset-cache!)
       (category/reset-cache!)
+      (dependencies/reset-cache!)
       (user-mappings/reset-cache!))))
 
 (def +test-api-key+ test-data/+test-api-key+) ;; re-exported for convenience