Browse Source

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.
travis-experimental
Christian Decker 4 years ago
committed by Rusty Russell
parent
commit
6f870dfe39
  1. 11
      contrib/pyln-testing/pyln/testing/db.py

11
contrib/pyln-testing/pyln/testing/db.py

@ -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)

Loading…
Cancel
Save