mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 01:24:26 +01:00
pytest: Don't give up on the first psql connection error
Since we start a new instance of postgres for each test we may end up swamped and the startup can take a bit longer. So let's loop until we get a success.
This commit is contained in:
committed by
Rusty Russell
parent
ee0ee046ff
commit
6f870dfe39
@@ -177,9 +177,14 @@ class PostgresDbProvider(object):
|
||||
'-F',
|
||||
'-i',
|
||||
])
|
||||
# Hacky but seems to work ok (might want to make the postgres proc a TailableProc as well if too flaky).
|
||||
time.sleep(1)
|
||||
self.conn = psycopg2.connect("dbname=template1 user=postgres host=localhost port={}".format(self.port))
|
||||
# Hacky but seems to work ok (might want to make the postgres proc a
|
||||
# TailableProc as well if too flaky).
|
||||
for i in range(30):
|
||||
try:
|
||||
self.conn = psycopg2.connect("dbname=template1 user=postgres host=localhost port={}".format(self.port))
|
||||
break
|
||||
except Exception:
|
||||
time.sleep(0.5)
|
||||
|
||||
# Required for CREATE DATABASE to work
|
||||
self.conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
|
||||
|
||||
Reference in New Issue
Block a user