Skip to content

Commit

Permalink
add waiting loop to ensure process is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
orm011 committed May 17, 2024
1 parent 605855b commit 64224dc
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/pgserver/postgres_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,19 @@ def ensure_postgres_running(self) -> None:
_logger.error(f"Timeout starting server.\nShowing contents of postgres server log ({self.log.absolute()}) below:\n{self.log.read_text()}")
raise err

self._postmaster_info = PostmasterInfo.read_from_pgdata(self.pgdata)
while True:
# in Windows, when there is a postmaster.pid, init_ctl seems to return
# but the file is not immediately updated, here we wait until the file shows
# a new running server. see test_stale_postmaster
_logger.info(f'waiting for postmaster info to show a running process')
pinfo = PostmasterInfo.read_from_pgdata(self.pgdata)
_logger.info(f'running... checking if ready {pinfo=}')
if pinfo is not None and pinfo.is_running() and pinfo.status == 'ready':
self._postmaster_info = pinfo
break

_logger.info(f'not ready yet... waiting a bit more...')
time.sleep(1.)

_logger.info(f"Now asserting server is running {self._postmaster_info=}")
assert self._postmaster_info is not None
Expand Down

0 comments on commit 64224dc

Please sign in to comment.