[devtools] make test db name for postgresql process-specific
authorJulien Cristau <julien.cristau@logilab.fr>
Mon, 18 May 2015 16:36:26 +0200
changeset 10438 f27a489994e8
parent 10437 9cddd711419c
child 10439 45e18b4a7466
[devtools] make test db name for postgresql process-specific In case we run two tests concurrently on the same cluster, better not use the same db name for both.
devtools/__init__.py
--- a/devtools/__init__.py	Mon May 18 16:30:32 2015 +0200
+++ b/devtools/__init__.py	Mon May 18 16:36:26 2015 +0200
@@ -585,6 +585,9 @@
             return
         _startpgcluster(datadir)
         self.__CTL.add(datadir)
+        if 'global-db-name' not in self.system_source:
+            self.system_source['global-db-name'] = self.system_source['db-name']
+            self.system_source['db-name'] = self.system_source['db-name'] + str(os.getpid())
 
     @property
     @cached
@@ -593,6 +596,10 @@
         return get_db_helper('postgres')
 
     @property
+    def dbname(self):
+        return self.system_source['global-db-name']
+
+    @property
     def dbcnx(self):
         try:
             return self._cnx
@@ -624,7 +631,7 @@
         from cubicweb.server.serverctl import system_source_cnx, createdb
         # connect on the dbms system base to create our base
         try:
-            self._drop(self.dbname)
+            self._drop(self.system_source['db-name'])
             createdb(self.helper, self.system_source, self.dbcnx, self.cursor)
             self.dbcnx.commit()
             cnx = system_source_cnx(self.system_source, special_privs='LANGUAGE C',
@@ -702,7 +709,7 @@
         """Actual restore of the current database.
 
         Use the value tostored in db_cache as input """
-        self._drop(self.dbname)
+        self._drop(self.system_source['db-name'])
         createdb(self.helper, self.system_source, self.dbcnx, self.cursor,
                  template=backup_coordinates)
         self.dbcnx.commit()