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

Commit2512835

Browse files
[#264] New property PostrgsNode::port_manager (#269)
This patch adds the RO-property PostgresNode::port_manager.This property returns a used port manager or None.Declaration of PostgresNode::_port_manager was corrected.New tests for PostgresNode::port_manager and PostgresNode::os_ops are added.
1 parenta7662d1 commit2512835

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

‎testgres/node.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class PostgresNode(object):
146146
_port:typing.Optional[int]
147147
_should_free_port:bool
148148
_os_ops:OsOperations
149-
_port_manager:PortManager
149+
_port_manager:typing.Optional[PortManager]
150150

151151
def__init__(self,
152152
name=None,
@@ -313,6 +313,11 @@ def os_ops(self) -> OsOperations:
313313
assertisinstance(self._os_ops,OsOperations)
314314
returnself._os_ops
315315

316+
@property
317+
defport_manager(self)->typing.Optional[PortManager]:
318+
assertself._port_managerisNoneorisinstance(self._port_manager,PortManager)
319+
returnself._port_manager
320+
316321
@property
317322
defname(self)->str:
318323
ifself._nameisNone:

‎tests/test_testgres_common.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,88 @@ def test_try_to_start_node_after_free_manual_port(self, node_svc: PostgresNodeSe
15031503
):
15041504
node2.start()
15051505

1506+
deftest_node__os_ops(self,node_svc:PostgresNodeService):
1507+
asserttype(node_svc)==PostgresNodeService# noqa: E721
1508+
1509+
assertnode_svc.os_opsisnotNone
1510+
assertisinstance(node_svc.os_ops,OsOperations)
1511+
1512+
withPostgresNode(name="node",os_ops=node_svc.os_ops,port_manager=node_svc.port_manager)asnode:
1513+
# retest
1514+
assertnode_svc.os_opsisnotNone
1515+
assertisinstance(node_svc.os_ops,OsOperations)
1516+
1517+
assertnode.os_opsisnode_svc.os_ops
1518+
# one more time
1519+
assertnode.os_opsisnode_svc.os_ops
1520+
1521+
deftest_node__port_manager(self,node_svc:PostgresNodeService):
1522+
asserttype(node_svc)==PostgresNodeService# noqa: E721
1523+
1524+
assertnode_svc.port_managerisnotNone
1525+
assertisinstance(node_svc.port_manager,PortManager)
1526+
1527+
withPostgresNode(name="node",os_ops=node_svc.os_ops,port_manager=node_svc.port_manager)asnode:
1528+
# retest
1529+
assertnode_svc.port_managerisnotNone
1530+
assertisinstance(node_svc.port_manager,PortManager)
1531+
1532+
assertnode.port_managerisnode_svc.port_manager
1533+
# one more time
1534+
assertnode.port_managerisnode_svc.port_manager
1535+
1536+
deftest_node__port_manager_and_explicit_port(self,node_svc:PostgresNodeService):
1537+
asserttype(node_svc)==PostgresNodeService# noqa: E721
1538+
1539+
assertisinstance(node_svc.os_ops,OsOperations)
1540+
assertnode_svc.port_managerisnotNone
1541+
assertisinstance(node_svc.port_manager,PortManager)
1542+
1543+
port=node_svc.port_manager.reserve_port()
1544+
asserttype(port)==int# noqa: E721
1545+
1546+
try:
1547+
withPostgresNode(name="node",port=port,os_ops=node_svc.os_ops)asnode:
1548+
# retest
1549+
assertisinstance(node_svc.os_ops,OsOperations)
1550+
assertnode_svc.port_managerisnotNone
1551+
assertisinstance(node_svc.port_manager,PortManager)
1552+
1553+
assertnode.port_managerisNone
1554+
assertnode.os_opsisnode_svc.os_ops
1555+
1556+
# one more time
1557+
assertnode.port_managerisNone
1558+
assertnode.os_opsisnode_svc.os_ops
1559+
finally:
1560+
node_svc.port_manager.release_port(port)
1561+
1562+
deftest_node__no_port_manager(self,node_svc:PostgresNodeService):
1563+
asserttype(node_svc)==PostgresNodeService# noqa: E721
1564+
1565+
assertisinstance(node_svc.os_ops,OsOperations)
1566+
assertnode_svc.port_managerisnotNone
1567+
assertisinstance(node_svc.port_manager,PortManager)
1568+
1569+
port=node_svc.port_manager.reserve_port()
1570+
asserttype(port)==int# noqa: E721
1571+
1572+
try:
1573+
withPostgresNode(name="node",port=port,os_ops=node_svc.os_ops,port_manager=None)asnode:
1574+
# retest
1575+
assertisinstance(node_svc.os_ops,OsOperations)
1576+
assertnode_svc.port_managerisnotNone
1577+
assertisinstance(node_svc.port_manager,PortManager)
1578+
1579+
assertnode.port_managerisNone
1580+
assertnode.os_opsisnode_svc.os_ops
1581+
1582+
# one more time
1583+
assertnode.port_managerisNone
1584+
assertnode.os_opsisnode_svc.os_ops
1585+
finally:
1586+
node_svc.port_manager.release_port(port)
1587+
15061588
@staticmethod
15071589
defhelper__get_node(
15081590
node_svc:PostgresNodeService,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp