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
Show file tree
Hide file tree
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
[#265] NodeApp.make_simple links a new node with own os_ops and port_…
…manager objects
  • Loading branch information
dmitry-lipetsk committed Jun 27, 2025
commit 488d5566f80ff053f8f3275b4ef894498707e956
28 changes: 25 additions & 3 deletions testgres/node_app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .node import OsOperations
from .node import LocalOperations
from .node import PostgresNode
from .node import PortManager

import os
import platform
Expand All @@ -13,23 +14,27 @@


class NodeApp:
_os_ops: OsOperations
_test_path: str
_os_ops: OsOperations
_port_manager: PortManager

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

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

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

if test_path is None:
self._test_path = os_ops.cwd()
Expand All @@ -45,6 +50,11 @@ def os_ops(self) -> OsOperations:
assert isinstance(self._os_ops, OsOperations)
return self._os_ops

@property
def port_manager(self) -> PortManager:
assert self._port_manager is None or isinstance(self._port_manager, PortManager)
return self._port_manager

@property
def test_path(self) -> str:
assert type(self._test_path) == str # noqa: E721
Expand Down Expand Up @@ -73,7 +83,19 @@ def make_empty(
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)
port_manager: PortManager = None

if port is None:
port_manager = self._port_manager

node = PostgresNode(
base_dir=real_base_dir,
port=port,
bin_dir=bin_dir,
os_ops=self._os_ops,
port_manager=port_manager
)

self.nodes_to_cleanup.append(node)

return node
Expand Down
38 changes: 38 additions & 0 deletions tests/test_testgres_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,44 @@ def test_node_app__make_empty__base_dir_is_Empty(self, node_svc: PostgresNodeSer
logging.info("temp directory [{}] is deleting".format(tmp_dir))
node_svc.os_ops.rmdir(tmp_dir)

def test_node_app__make_empty(self, node_svc: PostgresNodeService):
assert type(node_svc) == PostgresNodeService # noqa: E721

assert isinstance(node_svc.os_ops, OsOperations)
assert node_svc.port_manager is not None
assert isinstance(node_svc.port_manager, PortManager)

tmp_dir = node_svc.os_ops.mkdtemp()
assert tmp_dir is not None
assert type(tmp_dir) == str # noqa: E721
logging.info("temp directory is [{}]".format(tmp_dir))

# -----------
node_app = NodeApp(
test_path=tmp_dir,
os_ops=node_svc.os_ops,
port_manager=node_svc.port_manager
)

assert node_app.os_ops is node_svc.os_ops
assert node_app.port_manager is node_svc.port_manager

try:
node = node_app.make_simple("node")
assert node.os_ops is node_svc.os_ops
assert node.port_manager is node_svc.port_manager

node.slow_start()
except: # noqa: E722
node.stop()
raise

node.cleanup(release_resources=True)

# -----------
logging.info("temp directory [{}] is deleting".format(tmp_dir))
node_svc.os_ops.rmdir(tmp_dir)

def test_node_app__make_simple__checksum(self, node_svc: PostgresNodeService):
assert type(node_svc) == PostgresNodeService # noqa: E721

Expand Down
0