Make test database cache lookup concurrent
authorPhilippe Pepiot <philippe.pepiot@logilab.fr>
Fri, 26 Oct 2018 17:00:05 +0200
changeset 12356 ed486562ba7e
parent 12355 c703dc95c82e
child 12357 e385c9732f1e
Make test database cache lookup concurrent has_cache() is used to dertermine if the template database already exists or not. When running tests accross multiple process, has_cache() wasn't aware of databases created by other processes because it used a cache to generate the cache... Since the discovering discover_cached_db() time is quite reasonable (it's just about listing file in a directory), let re-generate the cache on cache miss.
cubicweb/devtools/__init__.py
--- a/cubicweb/devtools/__init__.py	Mon Oct 29 10:04:31 2018 +0100
+++ b/cubicweb/devtools/__init__.py	Fri Oct 26 17:00:05 2018 +0200
@@ -427,11 +427,12 @@
         raise ValueError('no initialization function for driver %r' % self.DRIVER)
 
     def has_cache(self, db_id):
-        """Check if a given database id exist in cb cache for the current config"""
-        cache_glob = self.absolute_backup_file('*', '*')
-        if cache_glob not in self.explored_glob:
-            self.discover_cached_db()
-        return self.db_cache_key(db_id) in self.db_cache
+        """Check if a given database id exist in db cache for the current config"""
+        key = self.db_cache_key(db_id)
+        if key in self.db_cache:
+            return True
+        self.discover_cached_db()
+        return key in self.db_cache
 
     def discover_cached_db(self):
         """Search available db_if for the current config"""