From aeb5f969e21894a4fe78736efb3a5039ea20c809 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 23 Sep 2020 16:51:38 +0200 Subject: [PATCH] pyln: Start each postgres DB in its own sub-directory We had a couple of issues with workers dying and attempting to re-initialize the database while it was already initialized. This will look for a free directory and just start the DB in there, allowing workers to be better isolated. --- contrib/pyln-testing/pyln/testing/db.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/contrib/pyln-testing/pyln/testing/db.py b/contrib/pyln-testing/pyln/testing/db.py index 6184f969c..804309981 100644 --- a/contrib/pyln-testing/pyln/testing/db.py +++ b/contrib/pyln-testing/pyln/testing/db.py @@ -1,6 +1,7 @@ from ephemeral_port_reserve import reserve from glob import glob +import itertools import logging import os import psycopg2 @@ -140,12 +141,20 @@ class PostgresDbProvider(object): def start(self): passfile = os.path.join(self.directory, "pgpass.txt") - self.pgdir = os.path.join(self.directory, 'pgsql') # Need to write a tiny file containing the password so `initdb` can # pick it up with open(passfile, 'w') as f: f.write('cltest\n') + # Look for a postgres directory that isn't taken yet. Not locking + # since this is run in a single-threaded context, at the start of each + # test. Multiple workers have separate directories, so they can't + # trample each other either. + for i in itertools.count(): + self.pgdir = os.path.join(self.directory, 'pgsql-{}'.format(i)) + if not os.path.exists(self.pgdir): + break + initdb, postgres = self.locate_path() subprocess.check_call([ initdb,