8000 TestTestgresCommon.test_the_same_port is added · postgrespro/testgres@1d450b2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1d450b2

Browse files
TestTestgresCommon.test_the_same_port is added
1 parent 0967057 commit 1d450b2

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

tests/test_testgres_common.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,16 +1141,46 @@ def test_unix_sockets(self, node_svc: PostgresNodeService):
11411141
res_psql = r.safe_psql('select 1')
11421142
assert (res_psql == b'1\n')
11431143

1144+
def test_the_same_port(self, node_svc: PostgresNodeService):
1145+
assert isinstance(node_svc, PostgresNodeService)
1146+
1147+
with __class__.helper__get_node(node_svc) as node:
1148+
node.init().start()
1149+
assert (node._should_free_port)
1150+
assert (type(node.port) == int) # noqa: E721
1151+
node_port_copy = node.port
1152+
r = node.safe_psql("SELECT 1;")
1153+
assert (__class__.helper__rm_carriage_returns(r) == b'1\n')
1154+
1155+
with __class__.helper__get_node(node_svc, port=node.port) as node2:
1156+
assert (type(node2.port) == int) # noqa: E721
1157+
assert (node2.port == node.port)
1158+
assert not (node2._should_free_port)
1159+
1160+
with pytest.raises(
1161+
expected_exception=StartNodeException,
1162+
match=re.escape("Cannot start node")
1163+
):
1164+
node2.init().start()
1165+
1166+
# node is still working
1167+
assert (node.port == node_port_copy)
1168+
assert (node._should_free_port)
1169+
r = node.safe_psql("SELECT 3;")
1170+
assert (__class__.helper__rm_carriage_returns(r) == b'3\n')
1171+
11441172
@staticmethod
1145-
def helper__get_node(node_svc: PostgresNodeService, name=None):
1173+
def helper__get_node(node_svc: PostgresNodeService, name=None, port=None):
11461174
assert isinstance(node_svc, PostgresNodeService)
11471175
assert isinstance(node_svc.os_ops, OsOperations)
11481176
assert isinstance(node_svc.port_manager, PortManager)
11491177
return PostgresNode(
11501178
name,
1179+
port=port,
11511180
conn_params=None,
11521181
os_ops=node_svc.os_ops,
1153-
port_manager=node_svc.port_manager)
1182+
port_manager=node_svc.port_manager if port is None else None
1183+
)
11541184

11551185
@staticmethod
11561186
def helper__skip_test_if_pg_version_is_not_ge(ver1: str, ver2: str):

tests/test_testgres_local.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -244,30 +244,6 @@ def test_parse_pg_version(self):
244244
# Macos
245245
assert parse_pg_version("postgres (PostgreSQL) 14.9 (Homebrew)") == "14.9"
246246

247-
def test_the_same_port(self):
248-
with get_new_node() as node:
249-
node.init().start()
250-
assert (node._should_free_port)
251-
assert (type(node.port) == int) # noqa: E721
252-
node_port_copy = node.port
253-
assert (rm_carriage_returns(node.safe_psql("SELECT 1;")) == b'1\n')
254-
255-
with get_new_node(port=node.port) as node2:
256-
assert (type(node2.port) == int) # noqa: E721
257-
assert (node2.port == node.port)
258-
assert not (node2._should_free_port)
259-
260-
with pytest.raises(
261-
expected_exception=StartNodeException,
262-
match=re.escape("Cannot start node")
263-
):
264-
node2.init().start()
265-
266-
# node is still working
267-
assert (node.port == node_port_copy)
268-
assert (node._should_free_port)
269-
assert (rm_carriage_returns(node.safe_psql("SELECT 3;")) == b'3\n')
270-
271247
class tagPortManagerProxy:
272248
sm_prev_testgres_reserve_port = None
273249
sm_prev_testgres_release_port = None

0 commit comments

Comments
 (0)
0