Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

testgres.os_ops 1.0.0 is used#298

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
dmitry-lipetsk wants to merge2 commits intopostgrespro:master
base:master
Choose a base branch
Loading
fromdmitry-lipetsk:D20251223_001--os_ops_1_0_0
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletionsDockerfile--std-all.tmpl
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ ENV PYTHON_VERSION=3
FROM base2_with_python-${PYTHON_VERSION} as final

#RUN apk add --no-cache mc
RUN apk add --no-cache git

# Full version of "ps" command
RUN apk add --no-cache procps
Expand Down
2 changes: 2 additions & 0 deletionsDockerfile--std.tmpl
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,8 @@ ENV PYTHON_VERSION=3
# --------------------------------------------- final
FROM base2_with_python-${PYTHON_VERSION} as final

RUN apk add --no-cache git

ENV LANG=C.UTF-8

ADD . /pg/testgres
Expand Down
2 changes: 2 additions & 0 deletionsDockerfile--ubuntu_24_04.tmpl
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -47,6 +47,8 @@ ENV PYTHON_VERSION=3
# --------------------------------------------- final
FROM base2_with_python-${PYTHON_VERSION} as final

RUN apt install -y git

ADD . /pg/testgres
WORKDIR /pg/testgres
RUN chown -R postgres /pg
Expand Down
2 changes: 1 addition & 1 deletiontests/requirements.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,4 +3,4 @@ pytest
pytest-xdist
psycopg2
six
testgres.os_ops>=0.0.2,<1.0.0
git+https://github.com/postgrespro/testgres.os_ops.git
199 changes: 199 additions & 0 deletionstests/test_os_ops_common.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@
from .helpers.run_conditions import RunConditions

import os
import sys

import pytest
import re
Expand All@@ -14,6 +15,10 @@
import threading
import typing
import uuid
import subprocess
import psutil
import time
import signal as os_signal

from src import InvalidOperationException
from src import ExecUtilException
Expand DownExpand Up@@ -1137,3 +1142,197 @@ class tadWorkerData:

logging.info("Test is finished! Total error count is {}.".format(nErrors))
return

T_KILL_SIGNAL_DESCR = typing.Tuple[
str,
typing.Union[int, os_signal.Signals],
str
]

sm_kill_signal_ids: typing.List[T_KILL_SIGNAL_DESCR] = [
("SIGINT", os_signal.SIGINT, "2"),
# ("SIGQUIT", os_signal.SIGQUIT, "3"), # it creates coredump
("SIGKILL", os_signal.SIGKILL, "9"),
("SIGTERM", os_signal.SIGTERM, "15"),
("2", 2, "2"),
# ("3", 3, "3"), # it creates coredump
("9", 9, "9"),
("15", 15, "15"),
]

@pytest.fixture(
params=sm_kill_signal_ids,
ids=["signal: {}".format(x[0]) for x in sm_kill_signal_ids],
)
def kill_signal_id(self, request: pytest.FixtureRequest) -> T_KILL_SIGNAL_DESCR:
assert isinstance(request, pytest.FixtureRequest)
assert type(request.param) == tuple # noqa: E721
return request.param

def test_kill_signal(
self,
kill_signal_id: T_KILL_SIGNAL_DESCR,
):
assert type(kill_signal_id) == tuple # noqa: E721
assert "{}".format(kill_signal_id[1]) == kill_signal_id[2]
assert "{}".format(int(kill_signal_id[1])) == kill_signal_id[2]

def test_kill(
self,
os_ops: OsOperations,
kill_signal_id: T_KILL_SIGNAL_DESCR,
):
"""
Test listdir for listing directory contents.
"""
assert isinstance(os_ops, OsOperations)
assert type(kill_signal_id) == tuple # noqa: E721

cmd = [
sys.executable,
"-c",
"import time; print('ENTER');time.sleep(300);print('EXIT')"
]

logging.info("Local test process is creating ...")
proc = subprocess.Popen(
cmd,
text=True,
)

assert proc is not None
assert type(proc) == subprocess.Popen # noqa: E721
proc_pid = proc.pid
assert type(proc_pid) == int # noqa: E721
logging.info("Test process pid is {}".format(proc_pid))

logging.info("Get this test process ...")
p1 = psutil.Process(proc_pid)
assert p1 is not None
del p1

logging.info("Kill this test process ...")
os_ops.kill(proc_pid, kill_signal_id[1])

logging.info("Wait for finish ...")
proc.wait()

logging.info("Try to get this test process ...")

attempt = 0
while True:
if attempt == 20:
raise RuntimeError("Process did not die.")

attempt += 1

if attempt > 1:
logging.info("Sleep 1 seconds...")
time.sleep(1)

try:
psutil.Process(proc_pid)
except psutil.ZombieProcess as e:
logging.info("Exception {}: {}".format(
type(e).__name__,
str(e),
))
except psutil.NoSuchProcess:
logging.info("OK. Process died.")
break

logging.info("Process is alive!")
continue

return

def test_kill__unk_pid(
self,
os_ops: OsOperations,
kill_signal_id: T_KILL_SIGNAL_DESCR,
):
"""
Test listdir for listing directory contents.
"""
assert isinstance(os_ops, OsOperations)
assert type(kill_signal_id) == tuple # noqa: E721

cmd = [
sys.executable,
"-c",
"import sys; print(\"a\", file=sys.stdout); print(\"b\", file=sys.stderr)"
]

logging.info("Local test process is creating ...")
proc = subprocess.Popen(
cmd,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)

assert proc is not None
assert type(proc) == subprocess.Popen # noqa: E721
proc_pid = proc.pid
assert type(proc_pid) == int # noqa: E721
logging.info("Test process pid is {}".format(proc_pid))

logging.info("Wait for finish ...")
pout, perr = proc.communicate()
logging.info("STDOUT: {}".format(pout))
logging.info("STDERR: {}".format(pout))
assert type(pout) == str # noqa: E721
assert type(perr) == str # noqa: E721
assert pout == "a\n"
assert perr == "b\n"
assert type(proc.returncode) == int # noqa: E721
assert proc.returncode == 0

logging.info("Try to get this test process ...")

attempt = 0
while True:
if attempt == 20:
raise RuntimeError("Process did not die.")

attempt += 1

if attempt > 1:
logging.info("Sleep 1 seconds...")
time.sleep(1)

try:
psutil.Process(proc_pid)
except psutil.ZombieProcess as e:
logging.info("Exception {}: {}".format(
type(e).__name__,
str(e),
))
except psutil.NoSuchProcess:
logging.info("OK. Process died.")
break

logging.info("Process is alive!")
continue

# --------------------
with pytest.raises(expected_exception=Exception) as x:
os_ops.kill(proc_pid, kill_signal_id[1])

assert x is not None
assert isinstance(x.value, Exception)
assert not isinstance(x.value, AssertionError)

logging.info("Our error is [{}]".format(str(x.value)))
logging.info("Our exception has type [{}]".format(type(x.value).__name__))

if type(os_ops).__name__ == "LocalOsOperations":
assert type(x.value) == ProcessLookupError # noqa: E721
assert "No such process" in str(x.value)
elif type(os_ops).__name__ == "RemoteOsOperations":
assert type(x.value) == ExecUtilException # noqa: E721
assert "No such process" in str(x.value)
else:
RuntimeError("Unknown os_ops type: {}".format(type(os_ops).__name__))

return

[8]ページ先頭

©2009-2025 Movatter.jp