Skip to content

Commit 65af0a4

Browse files
fix: test_status__force_clean_postmaster_pid was rewritten (#398)
- It tests a strange things - It fails under load
1 parent 852f69e commit 65af0a4

1 file changed

Lines changed: 49 additions & 13 deletions

File tree

‎tests/test_testgres_common.py‎

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,27 @@ def test_status__empty_postmaster_pid(self, node_svc: PostgresNodeService):
587587
assert expected_msg == x.value.error
588588
return
589589

590-
def test_status__force_clean_postmaster_pid(self, node_svc: PostgresNodeService):
590+
sm_false_true = [False, True]
591+
592+
@pytest.fixture(
593+
params=[
594+
pytest.param(
595+
x,
596+
id="sleep_after_clean={}".format(x),
597+
)
598+
for x in sm_false_true
599+
]
600+
)
601+
def sleep_after_clean(self, request: pytest.FixtureRequest) -> bool:
602+
assert isinstance(request, pytest.FixtureRequest)
603+
assert type(request.param) is bool
604+
return request.param
605+
606+
def test_status__force_clean_postmaster_pid(
607+
self,
608+
node_svc: PostgresNodeService,
609+
sleep_after_clean: bool,
610+
):
591611
assert isinstance(node_svc, PostgresNodeService)
592612

593613
assert (NodeStatus.Running)
@@ -611,27 +631,43 @@ def test_status__force_clean_postmaster_pid(self, node_svc: PostgresNodeService)
611631
postmaster_pid_file
612632
))
613633

634+
logging.info("Clean pid file...")
614635
node.os_ops.write(
615636
postmaster_pid_file,
616637
"",
617638
truncate=True,
618639
)
619640

620-
x = node.os_ops.read(
621-
postmaster_pid_file,
622-
encoding="utf-8",
623-
binary=False
624-
)
625-
assert x == ""
641+
if sleep_after_clean:
642+
# server removes pid file and shutdown within 60 seconds.
643+
logging.info("SLEEP 65 sec!")
644+
time.sleep(65)
626645

627-
with pytest.raises(expected_exception=ExecUtilException) as x:
628-
node.status()
646+
logging.info("Check node status...")
647+
node_status: typing.Optional[NodeStatus]
648+
try:
649+
node_status = node.status()
650+
except ExecUtilException as e:
651+
logging.info("Catch exception ({}): {}".format(
652+
type(e).__name__,
653+
str(e),
654+
))
629655

630-
expected_msg = "pg_ctl: the PID file \"{}\" is empty\n".format(
631-
postmaster_pid_file
632-
)
656+
expected_msg = "pg_ctl: the PID file \"{}\" is empty\n".format(
657+
postmaster_pid_file
658+
)
659+
assert expected_msg == e.error
660+
else:
661+
assert node_status is not None
633662

634-
assert expected_msg == x.value.error
663+
logging.info("Node Status is {}".format(node_status.name))
664+
665+
if node_status == NodeStatus.Stopped:
666+
pass
667+
elif node_status == NodeStatus.Zombie:
668+
logging.warning("Zombie is detected!")
669+
else:
670+
raise RuntimeError("Unknown node status: {}.".format(node_status))
635671
return
636672

637673
def test_kill__is_not_initialized(

0 commit comments

Comments
 (0)