Skip to content

get_pg_node_state can fail (PID file is empty) #329

@dmitry-lipetsk

Description

@dmitry-lipetsk

https://github.com/dmitry-lipetsk/testgres/actions/runs/21317871218/job/61363311353

________________ TestSet001__start.test_002__wait_false[local2] ________________
[gw1] linux -- Python 3.7.17 /tmp/testgres_venv/bin/python3

self = <tests.units.node.PostgresNode.test_setM001__start.TestSet001__start object at 0x7fb5b7bb5ad0>
node_svc = <tests.helpers.global_data.PostgresNodeService object at 0x7fb5b7a3f990>

    def test_002__wait_false(self, node_svc: PostgresNodeService):
        assert isinstance(node_svc, PostgresNodeService)
    
        C_MAX_ATTEMPTS = 3
    
        attempt = 0
    
        while True:
            assert type(attempt) == int  # noqa: E721
            assert attempt >= 0
            assert attempt <= C_MAX_ATTEMPTS
    
            if attempt == C_MAX_ATTEMPTS:
                raise RuntimeError("Node is not started")
    
            attempt += 1
    
            logging.info("------------- attempt #{}".format(attempt))
    
            if attempt > 1:
                HelperUtils.PrintAndSleep(5)
    
            with PostgresNodeTestUtils.get_node(node_svc) as node:
                assert type(node) == PostgresNode  # noqa: E721
                node.init()
                assert not node.is_started
                assert node.status() == NodeStatus.Stopped
    
                node_log_reader = PostgresNodeLogReader(node, from_beginnig=False)
                node.start(wait=False)
                assert node.is_started
                assert node.status() in [NodeStatus.Stopped,  NodeStatus.Running]
    
                # Internals
                assert type(node._manually_started_pm_pid) == int  # noqa: E721
                assert node._manually_started_pm_pid == node._C_PM_PID__IS_NOT_DETECTED
    
                logging.info("Wait for running state ...")
    
                try:
                    PostgresNodeTestUtils.wait_for_running_state(
                        node=node,
                        node_log_reader=node_log_reader,
>                       timeout=60,
                    )

C_MAX_ATTEMPTS = 3
attempt    = 1
node       = PostgresNode(name='testgres-9087a3b7-ddd4-433e-bd21-2b58b9bcb415', port=None, base_dir='/tmp/tgsn__ltrmhq7')
node_log_reader = <src.node.PostgresNodeLogReader object at 0x7fb5b6be43d0>
node_svc   = <tests.helpers.global_data.PostgresNodeService object at 0x7fb5b7a3f990>
self       = <tests.units.node.PostgresNode.test_setM001__start.TestSet001__start object at 0x7fb5b7bb5ad0>

tests/units/node/PostgresNode/test_setM001__start.py:130: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/helpers/pg_node_utils.py:168: in wait_for_running_state
    s = node.status()
        _          = None
        __class__  = <class 'tests.helpers.pg_node_utils.PostgresNodeUtils'>
        node       = PostgresNode(name='testgres-9087a3b7-ddd4-433e-bd21-2b58b9bcb415', port=None, base_dir='/tmp/tgsn__ltrmhq7')
        node_log_reader = <src.node.PostgresNodeLogReader object at 0x7fb5b6be43d0>
        timeout    = 60
src/node.py:930: in status
    x = self._get_node_state()
        self       = PostgresNode(name='testgres-9087a3b7-ddd4-433e-bd21-2b58b9bcb415', port=None, base_dir='/tmp/tgsn__ltrmhq7')
src/node.py:939: in _get_node_state
    self.utils_log_file
        self       = PostgresNode(name='testgres-9087a3b7-ddd4-433e-bd21-2b58b9bcb415', port=None, base_dir='/tmp/tgsn__ltrmhq7')
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

os_ops = <testgres.operations.local_ops.LocalOperations object at 0x7fb5b85d4e50>
bin_dir = '/usr/local/bin', data_dir = '/tmp/tgsn__ltrmhq7/data'
utils_log_file = '/tmp/tgsn__ltrmhq7/logs/utils.log'

    def get_pg_node_state(
        os_ops: OsOperations,
        bin_dir: str,
        data_dir: str,
        utils_log_file: typing.Optional[str],
    ) -> PostgresNodeState:
        assert isinstance(os_ops, OsOperations)
        assert type(bin_dir) == str  # noqa: E721
        assert type(data_dir) == str  # noqa: E721
        assert utils_log_file is None or type(utils_log_file) == str  # noqa: E721
    
        _params = [
            os_ops.build_path(bin_dir, "pg_ctl"),
            "-D",
            data_dir,
            "status",
        ]
    
        status_code, out, error = execute_utility2(
            os_ops,
            _params,
            utils_log_file,
            verbose=True,
            ignore_errors=True,
        )
    
        assert type(status_code) == int  # noqa: E721
        assert type(out) == str  # noqa: E721
        assert type(error) == str  # noqa: E721
    
        # -----------------
        if status_code == PG_CTL__STATUS__NODE_IS_STOPPED:
            return PostgresNodeState(NodeStatus.Stopped, None)
    
        # -----------------
        if status_code == PG_CTL__STATUS__BAD_DATADIR:
            return PostgresNodeState(NodeStatus.Uninitialized, None)
    
        # -----------------
        if status_code != PG_CTL__STATUS__OK:
            errMsg = "Getting of a node status [data_dir is {0}] failed.".format(
                data_dir
            )
    
            raise ExecUtilException(
                message=errMsg,
                command=_params,
                exit_code=status_code,
                out=out,
>               error=error,
            )
E           testgres.operations.exceptions.ExecUtilException: Getting of a node status [data_dir is /tmp/tgsn__ltrmhq7/data] failed.
E           Command: /usr/local/bin/pg_ctl -D /tmp/tgsn__ltrmhq7/data status
E           Exit code: 1
E           ---- Error:
E           pg_ctl: the PID file "/tmp/tgsn__ltrmhq7/data/postmaster.pid" is empty

_params    = ['/usr/local/bin/pg_ctl', '-D', '/tmp/tgsn__ltrmhq7/data', 'status']
bin_dir    = '/usr/local/bin'
data_dir   = '/tmp/tgsn__ltrmhq7/data'
errMsg     = 'Getting of a node status [data_dir is /tmp/tgsn__ltrmhq7/data] failed.'
error      = 'pg_ctl: the PID file "/tmp/tgsn__ltrmhq7/data/postmaster.pid" is empty\n'
os_ops     = <testgres.operations.local_ops.LocalOperations object at 0x7fb5b85d4e50>
out        = ''
status_code = 1
utils_log_file = '/tmp/tgsn__ltrmhq7/logs/utils.log'

src/utils.py:392: ExecUtilException

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions