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

Commitb1cee19

Browse files
PortManager was deleted [amen]
1 parent17c73cb commitb1cee19

File tree

6 files changed

+32
-51
lines changed

6 files changed

+32
-51
lines changed

‎testgres/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@
5454
from .operations.local_opsimportLocalOperations
5555
from .operations.remote_opsimportRemoteOperations
5656

57-
from .helpers.port_managerimportPortManager
58-
5957
__all__= [
6058
"get_new_node",
6159
"get_remote_node",
@@ -67,6 +65,6 @@
6765
"PostgresNode","NodeApp",
6866
"PostgresNodePortManager",
6967
"reserve_port","release_port","bound_ports","get_bin_path","get_pg_config","get_pg_version",
70-
"First","Any","PortManager",
68+
"First","Any",
7169
"OsOperations","LocalOperations","RemoteOperations","ConnectionParams"
7270
]

‎testgres/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ class TestgresException(Exception):
77
pass
88

99

10+
classPortForException(TestgresException):
11+
pass
12+
13+
1014
@six.python_2_unicode_compatible
1115
classExecUtilException(TestgresException):
1216
def__init__(self,message=None,command=None,exit_code=0,out=None,error=None):

‎testgres/helpers/__init__.py

Whitespace-only changes.

‎testgres/helpers/port_manager.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

‎testgres/port_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from .operations.os_opsimportOsOperations
22

3-
from .helpers.port_managerimportPortForException
3+
from .exceptionsimportPortForException
44

55
from .importutils
66

77
importthreading
88
importrandom
99

10+
1011
classPostgresNodePortManager:
1112
def__init__(self):
1213
super().__init__()

‎testgres/utils.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
importos
77

88
importsys
9+
importsocket
10+
importrandom
911

1012
fromcontextlibimportcontextmanager
1113
frompackaging.versionimportVersion,InvalidVersion
1214
importre
1315

1416
fromsiximportiteritems
1517

16-
from .helpers.port_managerimportPortManager
18+
from .exceptionsimportPortForException
1719
from .exceptionsimportExecUtilException
1820
from .configimporttestgres_configastconf
1921
from .operations.os_opsimportOsOperations
@@ -41,11 +43,28 @@ def internal__reserve_port():
4143
"""
4244
Generate a new port and add it to 'bound_ports'.
4345
"""
44-
port_mng=PortManager()
45-
port=port_mng.find_free_port(exclude_ports=bound_ports)
46-
bound_ports.add(port)
47-
48-
returnport
46+
defLOCAL__is_port_free(port:int)->bool:
47+
"""Check if a port is free to use."""
48+
withsocket.socket(socket.AF_INET,socket.SOCK_STREAM)ass:
49+
try:
50+
s.bind(("",port))
51+
returnTrue
52+
exceptOSError:
53+
returnFalse
54+
55+
ports=set(range(1024,65535))
56+
asserttype(ports)==set# noqa: E721
57+
asserttype(bound_ports)==set# noqa: E721
58+
ports.difference_update(bound_ports)
59+
60+
sampled_ports=random.sample(tuple(ports),min(len(ports),100))
61+
62+
forportinsampled_ports:
63+
ifLOCAL__is_port_free(port):
64+
bound_ports.add(port)
65+
returnport
66+
67+
raisePortForException("Can't select a port")
4968

5069

5170
definternal__release_port(port):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp