Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgresNode::pid is improved #199

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dmitry-lipetsk
Copy link
Collaborator

  • We do multiple attempts to read pid file.
  • We process a case when we see that node is stopped between test and read.
  • We process a case when pid-file is empty.

- We do multiple attempts to read pid file.
- We process a case when we see that node is stopped between test and read.
- We process a case when pid-file is empty.
@dmitry-lipetsk
Copy link
Collaborator Author

Example of problem with PostgresNode.pid:
https://app.travis-ci.com/github/postgrespro/testgres/jobs/630950715

____________________ TestgresTests.test_pg_ctl_wait_option _____________________
[gw3] linux -- Python 3.12.3 /tmp/testgres_venv/bin/python
self = <testgres.tests.test_simple.TestgresTests object at 0x7fbc7ed0e900>
    def test_pg_ctl_wait_option(self):
>       with get_new_node() as node:
node       = PostgresNode(name='testgres-3103c943-9757-416e-b7c5-55899be2539e', port=None, base_dir='/tmp/tgsn_05zpeoer')
self       = <testgres.tests.test_simple.TestgresTests object at 0x7fbc7ed0e900>
tests/test_simple.py:431: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
testgres/node.py:197: in __exit__
    self.cleanup(attempts)
        attempts   = 3
        c1         = True
        c2         = False
        got_exception = False
        self       = PostgresNode(name='testgres-3103c943-9757-416e-b7c5-55899be2539e', port=None, base_dir='/tmp/tgsn_05zpeoer')
        traceback  = None
        type       = None
        value      = None
testgres/node.py:1040: in cleanup
    self._try_shutdown(max_attempts)
        full       = False
        max_attempts = 3
        self       = PostgresNode(name='testgres-3103c943-9757-416e-b7c5-55899be2539e', port=None, base_dir='/tmp/tgsn_05zpeoer')
testgres/node.py:342: in _try_shutdown
    node_pid = self.pid
        attempts   = 0
        max_attempts = 3
        self       = PostgresNode(name='testgres-3103c943-9757-416e-b7c5-55899be2539e', port=None, base_dir='/tmp/tgsn_05zpeoer')
        with_force = False
testgres/node.py:213: in pid
    lines = self.os_ops.readlines(pid_file)
        pid_file   = '/tmp/tgsn_05zpeoer/data/postmaster.pid'
        self       = PostgresNode(name='testgres-3103c943-9757-416e-b7c5-55899be2539e', port=None, base_dir='/tmp/tgsn_05zpeoer')
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = <testgres.testgres.operations.local_ops.LocalOperations object at 0x7fbc7edc9640>
filename = '/tmp/tgsn_05zpeoer/data/postmaster.pid', num_lines = 0
binary = False, encoding = None
    def readlines(self, filename, num_lines=0, binary=False, encoding=None):
        """
        Read lines from a local file.
        If num_lines is greater than 0, only the last num_lines lines will be read.
        """
        assert num_lines >= 0
        mode = 'rb' if binary else 'r'
        if num_lines == 0:
>           with open(filename, mode, encoding=encoding) as file:  # open in binary mode
E           FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tgsn_05zpeoer/data/postmaster.pid'
binary     = False
encoding   = None
filename   = '/tmp/tgsn_05zpeoer/data/postmaster.pid'
mode       = 'r'
num_lines  = 0
self       = <testgres.testgres.operations.local_ops.LocalOperations object at 0x7fbc7edc9640>
testgres/operations/local_ops.py:341: FileNotFoundError

@dmitry-lipetsk
Copy link
Collaborator Author

The current implementation of PostgresNode::pid() is bad.

We have to check and use the information from pg_ctl:

dima@ubuntu-work-01:/home$ pg_ctl status
pg_ctl: server is running (PID: 2864920)
/usr/local/pgsql/bin/postgres

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant