From 95eb868047aad17e4ab2b1f546f40c49c0a9247c Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 28 Jan 2022 22:53:10 +0100 Subject: [PATCH] pyln: Delete psql DBs after testing --- contrib/pyln-testing/pyln/testing/db.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/contrib/pyln-testing/pyln/testing/db.py b/contrib/pyln-testing/pyln/testing/db.py index efcd345dc..5ee90ce79 100644 --- a/contrib/pyln-testing/pyln/testing/db.py +++ b/contrib/pyln-testing/pyln/testing/db.py @@ -51,6 +51,9 @@ class Sqlite3Db(object): c.close() db.close() + def stop(self): + pass + class PostgresDb(object): def __init__(self, dbname, port): @@ -88,6 +91,15 @@ class PostgresDb(object): with self.conn, self.conn.cursor() as cur: cur.execute(query) + def stop(self): + """Clean up the database. + """ + self.conn.close() + conn = psycopg2.connect("dbname=postgres user=postgres host=localhost port={self.port}") + cur = conn.cursor() + cur.execute("DROP DATABASE {};".format(self.dbname)) + cur.close() + class SqliteDbProvider(object): def __init__(self, directory: str) -> None: @@ -208,3 +220,4 @@ class PostgresDbProvider(object): # [1] https://www.postgresql.org/docs/9.1/server-shutdown.html self.proc.send_signal(signal.SIGINT) self.proc.wait() + shutil.rmtree(self.pgdir)