8000 NodeApp is refactored by dmitry-lipetsk · Pull Request #278 · postgrespro/testgres · GitHub
[go: up one dir, main page]

Skip to content

NodeApp is refactored #278

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

Merged
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
17fb8c3
NodeApp was moved to own py-file (refactoring)
dmitry-lipetsk Jun 26, 2025
8eaa289
NodeApp is refactored totally
dmitry-lipetsk Jun 26, 2025
2246447
NodeApp::test_path is corrected
dmitry-lipetsk Jun 26, 2025
3fe3e94
Default value of 'pg_options' (NodeApp::make_simple) is None
dmitry-lipetsk Jun 27, 2025
c1afd7e
Merge branch 'master' into D20250626_001--node_app
dmitry-lipetsk Jun 27, 2025
1062a97
OsOperations::create_clone is added
dmitry-lipetsk Jun 27, 2025
1512fe7
[#277] NodeApp::make_empty does not allow None/empty base_dir
dmitry-lipetsk Jun 27, 2025
b5b0d2b
[#267] NodeApp.make_simple does not change 'initdb_params'
dmitry-lipetsk Jun 27, 2025
dffde2c
test_node_app__make_empty__base_dir_is_None is corrected
dmitry-lipetsk Jun 27, 2025
d5c3672
NodeApp::make_simple is corrected (bad assert)
dmitry-lipetsk Jun 27, 2025
aae53eb
test_node_app__make_empty__base_dir_is_xxx is updated
dmitry-lipetsk Jun 27, 2025
488d556
[#265] NodeApp.make_simple links a new node with own os_ops and port_…
dmitry-lipetsk Jun 27, 2025
688b89f
test_node_app__make_empty is corrected
dmitry-lipetsk Jun 27, 2025
4f85ce5
NodeApp::nodes_to_cleanup is RO-property
dmitry-lipetsk Jun 27, 2025
f79e9a7
flake8
dmitry-lipetsk Jun 27, 2025
5817f63
test_node_app__make_empty is fixed
dmitry-lipetsk Jun 28, 2025
0547b0b
PostgresNode::release_resources(self) is added
dmitry-lipetsk Jun 28, 2025
1b12ca3
[FIX] NodeApp::make_empty processes a failure of self._nodes_to_clean…
dmitry-lipetsk Jun 28, 2025
1af3dfa
New test test_node_app__make_empty_with_explicit_port is added
dmitry-lipetsk Jun 28, 2025
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
Prev Previous commit
Next Next commit
NodeApp is refactored totally
  • Loading branch information
dmitry-lipetsk committed Jun 26, 2025
commit 8eaa2892f5266c645b8e9e0e7b4c18959c0bf5e4
103 changes: 75 additions & 28 deletions testgres/node_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,67 @@
import os
import platform
import tempfile
import typing


class NodeApp:
T_DICT_STR_STR = typing.Dict[str, str]
T_LIST_STR = typing.List[str]


def __init__(self, test_path=None, nodes_to_cleanup=None, os_ops=None):
class NodeApp:
_os_ops: OsOperations
_test_path: str

def __init__(
self,
test_path: typing.Optional[str] = None,
nodes_to_cleanup: typing.Optional[list] = None,
os_ops: typing.Optional[OsOperations] = None
):
assert test_path is None or type(test_path) == str # noqa: E721
assert os_ops is None or isinstance(os_ops, OsOperations)

if os_ops is None:
os_ops = LocalOperations.get_single_instance()

assert isinstance(os_ops, OsOperations)
self._os_ops = os_ops

if test_path:
if os.path.isabs(test_path):
self.test_path = test_path
8000 else:
self.test_path = os_ops.build_path(os_ops.cwd(), test_path)
if test_path is None:
self._test_path = os_ops.cwd()
elif os.path.isabs(test_path):
self._test_path = test_path
else:
self.test_path = os_ops.cwd()
self._test_path = os_ops.build_path(os_ops.cwd(), test_path)

self.nodes_to_cleanup = nodes_to_cleanup if nodes_to_cleanup else []
self.os_ops = os_ops

@property
def os_ops(self) -> OsOperations:
assert isinstance(self._os_ops, OsOperations)
return self._os_ops

@property
def test_path(self) -> str:
assert isinstance(self._test_path, OsOperations)
return self._test_path

def make_empty(
self,
base_dir=None,
port=None,
bin_dir=None):
real_base_dir = self.os_ops.build_path(self.test_path, base_dir)
self.os_ops.rmdirs(real_base_dir, ignore_errors=True)
self.os_ops.makedirs(real_base_dir)
base_dir: typing.Optional[str] = None,
port: typing.Optional[int] = None,
bin_dir: typing.Optional[str] = None
) -> PostgresNode:
assert base_dir is None or type(base_dir) == str # noqa: E721
assert port is None or type(port) == int # noqa: E721
assert bin_dir is None or type(bin_dir) == str # noqa: E721

assert isinstance(self._os_ops, OsOperations)
assert type(self._test_path) == str # noqa: E721

real_base_dir = self._os_ops.build_path(self._test_path, base_dir)
self._os_ops.rmdirs(real_base_dir, ignore_errors=True)
self._os_ops.makedirs(real_base_dir)

node = PostgresNode(base_dir=real_base_dir, port=port, bin_dir=bin_dir)
self.nodes_to_cleanup.append(node)
Expand All @@ -43,24 +74,40 @@ def make_empty(

def make_simple(
self,
base_dir=None,
port=None,
set_replication=False,
ptrack_enable=False,
initdb_params=[],
pg_options={},
checksum=True,
bin_dir=None):
base_dir: typing.Optional[str] = None,
port: typing.Optional[int] = None,
set_replication: bool = False,
ptrack_enable: bool = False,
initdb_params: T_LIST_STR = [],
pg_options: T_DICT_STR_STR = {},
checksum: bool = True,
bin_dir: typing.Optional[str] = None
) -> PostgresNode:
assert base_dir is None or type(base_dir) == str # noqa: E721
assert port is None or type(port) == int # noqa: E721
assert type(set_replication) == bool # noqa: E721
assert type(ptrack_enable) == bool # noqa: E721
assert type(initdb_params) == list # noqa: E721
assert type(pg_options) == dict # noqa: E721
assert type(checksum) == bool # noqa: E721
assert bin_dir is None or type(bin_dir) == str # noqa: E721

if checksum and '--data-checksums' not in initdb_params:
initdb_params.append('--data-checksums')
node = self.make_empty(base_dir, port, bin_dir=bin_dir)

node = self.make_empty(
base_dir,
port,
bin_dir=bin_dir
)

node.init(
initdb_params=initdb_params, allow_streaming=set_replication)
initdb_params=initdb_params,
allow_streaming=set_replication
)

# set major version
pg_version_file = self.os_ops.read(self.os_ops.build_path(node.data_dir, 'PG_VERSION'))
pg_version_file = self._os_ops.read(self._os_ops.build_path(node.data_dir, 'PG_VERSION'))
node.major_version_str = str(pg_version_file.rstrip())
node.major_version = float(node.major_version_str)

Expand Down Expand Up @@ -115,7 +162,7 @@ def make_simple(
return node

@staticmethod
def _gettempdir_for_socket():
def _gettempdir_for_socket() -> str:
platform_system_name = platform.system().lower()

if platform_system_name == "windows":
Expand Down Expand Up @@ -143,7 +190,7 @@ def _gettempdir_for_socket():
return "/tmp"

@staticmethod
def _gettempdir():
def _gettempdir() -> str:
v = tempfile.gettempdir()

#
Expand Down
0