[devtools] Make PostgresTestDataBaseHandler multi-use friendly
authorChristophe de Vienne <christophe@unlish.com>
Wed, 28 Jan 2015 14:03:00 +0100
changeset 10175 2659f8529a43
parent 10174 7e1c8fb9c407
child 10176 7d3a583ed539
[devtools] Make PostgresTestDataBaseHandler multi-use friendly Dont init the pgdb twice on the same datadir - If two test case with the same apphome use a Postgres configuration, the handler is initialised twice, so it has to check if the pgdb directory has already been initialized. - Work with the realpath of the pgdb In some cases, the self.config.apphome will resolve symbolic links, but not always. It can result in an attempt to start twice the pg server for the same directory, in the same test run... resulting in failure. Closes #4875827
devtools/__init__.py
--- a/devtools/__init__.py	Mon Feb 02 12:07:10 2015 +0100
+++ b/devtools/__init__.py	Wed Jan 28 14:03:00 2015 +0100
@@ -33,7 +33,7 @@
 import getpass
 from hashlib import sha1 # pylint: disable=E0611
 from datetime import timedelta
-from os.path import (abspath, join, exists, split, isabs, isdir)
+from os.path import (abspath, realpath, join, exists, split, isabs, isdir)
 from functools import partial
 
 from logilab.common.date import strptime
@@ -549,7 +549,9 @@
 
     def __init__(self, *args, **kwargs):
         super(PostgresTestDataBaseHandler, self).__init__(*args, **kwargs)
-        datadir = join(self.config.apphome, 'pgdb')
+        datadir = realpath(join(self.config.apphome, 'pgdb'))
+        if datadir in self.__CTL:
+            return
         if not exists(datadir):
             try:
                 subprocess.check_call(['initdb', '-D', datadir, '-E', 'utf-8', '--locale=C'])