Skip to content

Commit

Permalink
skip pgctl test if running as root. add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
orm011 committed May 17, 2024
1 parent d4c5cfd commit 4f2b5c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/pgserver/postgres_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def ensure_pgdata_inited(self) -> None:
#
# Since we do not know PID information of the old server, we stop all servers with the same pgdata path.
# way to test this: python -c 'import pixeltable as pxt; pxt.Client()'; rm -rf ~/.pixeltable/; python -c 'import pixeltable as pxt; pxt.Client()'
_logger.info('no PG_VERSION file found, initializing pgdata')
_logger.info(f'no PG_VERSION file found within {self.pgdata}. Initializing pgdata')
for proc in psutil.process_iter(attrs=['name', 'cmdline']):
if proc.info['name'] == 'postgres':
if proc.info['cmdline'] is not None and str(self.pgdata) in proc.info['cmdline']:
Expand Down Expand Up @@ -138,11 +138,13 @@ def ensure_postgres_running(self) -> None:
postmaster_info = PostmasterInfo.read_from_pgdata(self.pgdata)
if postmaster_info is not None and postmaster_info.is_running():
self._postmaster_info = postmaster_info
_logger.info(f"server already running: {self._postmaster_info=} {self._postmaster_info.process=}")
_logger.info(f"a postgres server is already running: {self._postmaster_info=} {self._postmaster_info.process=}")

if self._postmaster_info.status != 'ready':
_logger.warning(f"server running but somehow not ready: {self._postmaster_info=}")
_logger.warning(f"the server is running but not ready (unexpected) {self._postmaster_info=}")
else:
_logger.info(f"no postgres server found running, assuming stale {self._postmaster_info=} {self._postmaster_info.process=}")

if platform.system() != 'Windows':
# use sockets to avoid any future conflict with port numbers
socket_dir = find_suitable_socket_dir(self.pgdata, self.runtime_path)
Expand Down
7 changes: 7 additions & 0 deletions tests/test_pgserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import datetime
from sqlalchemy_utils import database_exists, create_database
import logging
import os

def _check_sqlalchemy_works(srv : pgserver.PostgresServer):
database_name = 'testdb'
Expand Down Expand Up @@ -172,6 +173,12 @@ def test_unix_domain_socket():
_kill_server(pid)

def test_pg_ctl():
if platform.system() != 'Windows' and os.geteuid() == 0:
# on Linux root, this test would fail.
# we'd need to create a user etc to run the command, which is not worth it
# pgserver does this internally, but not worth it for this test
pytest.skip("This test is not run as root on Linux.")

with tempfile.TemporaryDirectory() as tmpdir:
pid = None
try:
Expand Down

0 comments on commit 4f2b5c6

Please sign in to comment.