[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

authorChristophe de Vienne <christophe@unlish.com>
changeset2659f8529a43
branchdefault
phasepublic
hiddenno
parent revision#7e1c8fb9c407 [devtools] restore i18n of string removed in 4001cfe2f44d
child revision#7d3a583ed539 [debian] build-depend on markdown for documentation build
files modified by this revision
devtools/__init__.py
# HG changeset patch
# User Christophe de Vienne <christophe@unlish.com>
# Date 1422450180 -3600
# Wed Jan 28 14:03:00 2015 +0100
# Node ID 2659f8529a43ecdf4d386c62a975e63c760bee93
# Parent 7e1c8fb9c4070d63c88925768376f92a0a9152f9
[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

diff --git a/devtools/__init__.py b/devtools/__init__.py
@@ -31,11 +31,11 @@
1  import warnings
2  import tempfile
3  import getpass
4  from hashlib import sha1 # pylint: disable=E0611
5  from datetime import timedelta
6 -from os.path import (abspath, join, exists, split, isabs, isdir)
7 +from os.path import (abspath, realpath, join, exists, split, isabs, isdir)
8  from functools import partial
9 
10  from logilab.common.date import strptime
11  from logilab.common.decorators import cached, clear_cache
12 
@@ -547,11 +547,13 @@
13          for datadir in cls.__CTL:
14              subprocess.call(['pg_ctl', 'stop', '-D', datadir, '-m', 'fast'])
15 
16      def __init__(self, *args, **kwargs):
17          super(PostgresTestDataBaseHandler, self).__init__(*args, **kwargs)
18 -        datadir = join(self.config.apphome, 'pgdb')
19 +        datadir = realpath(join(self.config.apphome, 'pgdb'))
20 +        if datadir in self.__CTL:
21 +            return
22          if not exists(datadir):
23              try:
24                  subprocess.check_call(['initdb', '-D', datadir, '-E', 'utf-8', '--locale=C'])
25 
26              except OSError, err: