Skip to content

Commit

Permalink
Issue #339
Browse files Browse the repository at this point in the history
Status checks for running postgres depend on pg_ctl status code, not on pg_ctl log language
  • Loading branch information
zoowirt committed Oct 7, 2020
1 parent fbced46 commit e4b5d2a
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions src/pytest_postgresql/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,12 @@ def wait_for_postgres(self):
start_info = 'database system is ready to accept connections'
# wait for expected message.
while 1:
with open(self.logfile, 'r') as content_file:
content = content_file.read()
if start_info in content:
break
status_code = subprocess.getstatusoutput(
'{pg_ctl} status -D {datadir}'.format(
pg_ctl=self.executable,
datadir=self.datadir))[0]
if status_code == 0:
break
time.sleep(1)

def proc_start_command(self):
Expand All @@ -202,22 +204,13 @@ def running(self):
"""Check if server is still running."""
if not os.path.exists(self.datadir):
return False

status_code = subprocess.getstatusoutput(
'{pg_ctl} status -D {datadir}'.format(
pg_ctl=self.executable,
datadir=self.datadir))[0]

try:
output = subprocess.check_output(
'{pg_ctl} status -D {datadir}'.format(
pg_ctl=self.executable,
datadir=self.datadir
),
env=self._popen_kwargs['env'],
shell=True
).decode('utf-8')
except subprocess.CalledProcessError as ex:
if b'pg_ctl: no server running' in ex.output:
return False
raise

return "pg_ctl: server is running" in output
return status_code == 0

def stop(self,
sig: int = None,
Expand Down

0 comments on commit e4b5d2a

Please sign in to comment.