[devtool] Make the sqlite database used for test execution process specific (closes #1230401) stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 01 Aug 2011 17:58:28 +0200
branchstable
changeset 7722 fb231d62adda
parent 7720 4df02855f4b3
child 7723 badfd5524ab6
[devtool] Make the sqlite database used for test execution process specific (closes #1230401) * Database cache are not impacted. * This allow multiple process to run test with the same template at the same time The db-name property return an unaltered value to for database cache mechanism.
devtools/__init__.py
--- a/devtools/__init__.py	Wed Jul 27 20:15:44 2011 +0200
+++ b/devtools/__init__.py	Mon Aug 01 17:58:28 2011 +0200
@@ -657,6 +657,24 @@
 class SQLiteTestDataBaseHandler(TestDataBaseHandler):
     DRIVER = 'sqlite'
 
+    __TMPDB = set()
+
+    @classmethod
+    def _cleanup_all_tmpdb(cls):
+        for dbpath in cls.__TMPDB:
+            cls._cleanup_database(dbpath)
+
+
+
+    def __init__(self, *args, **kwargs):
+        super(SQLiteTestDataBaseHandler, self).__init__(*args, **kwargs)
+        # use a dedicated base for each process.
+        if 'global-db-name' not in self.system_source:
+            self.system_source['global-db-name'] = self.system_source['db-name']
+            process_db = self.system_source['db-name'] + str(os.getpid())
+            self.__TMPDB.add(process_db)
+            self.system_source['db-name'] = process_db
+
     @staticmethod
     def _cleanup_database(dbfile):
         try:
@@ -665,6 +683,10 @@
         except OSError:
             pass
 
+    @property
+    def dbname(self):
+        return self.system_source['global-db-name']
+
     def absolute_dbfile(self):
         """absolute path of current database file"""
         dbfile = join(self._ensure_test_backup_db_dir(),
@@ -707,6 +729,9 @@
         self._cleanup_database(self.absolute_dbfile())
         init_repository(self.config, interactive=False)
 
+import atexit
+atexit.register(SQLiteTestDataBaseHandler._cleanup_all_tmpdb)
+
 
 def install_sqlite_patch(querier):
     """This patch hotfixes the following sqlite bug :