Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Rafael Monnerat
erp5
Commits
3e7b1fff
Commit
3e7b1fff
authored
Jan 15, 2025
by
Rafael Monnerat
👻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
caucasexx: update to findFreeTCPPortRange
parent
46f48451
Pipeline
#40091
failed with stage
in 0 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
13 deletions
+24
-13
product/ERP5Type/tests/ERP5TypeCaucaseTestCase.py
product/ERP5Type/tests/ERP5TypeCaucaseTestCase.py
+24
-13
No files found.
product/ERP5Type/tests/ERP5TypeCaucaseTestCase.py
View file @
3e7b1fff
...
...
@@ -29,17 +29,14 @@
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
Products.ERP5Type.tests.utils
import
parseListeningAddress
from
six
import
BytesIO
import
socket
import
time
import
os
import
shutil
import
contextlib
import
multiprocessing
import
requests
import
tarfile
from
random
import
randint
import
random
import
contextlib
import
caucase.cli
import
caucase.http
...
...
@@ -54,13 +51,27 @@ def canConnect(caucase_url):
return
False
return
True
def
findFreeTCPPort
(
ip
=
''
):
"""Find a free TCP port to listen to.
def
findFreeTCPPortRange
(
ip
=
''
,
count
=
1
):
# type: (str, int) -> int
"""Find a range of consecutive `count` free TCP ports to listen to.
"""
family
=
socket
.
AF_INET6
if
':'
in
ip
else
socket
.
AF_INET
with
contextlib
.
closing
(
socket
.
socket
(
family
,
socket
.
SOCK_STREAM
))
as
s
:
s
.
bind
((
ip
,
0
))
return
str
(
s
.
getsockname
()[
1
])
for
_
in
range
(
10
):
# retry 10 times
port
=
random
.
randrange
(
20000
,
30000
)
for
offset
in
range
(
count
):
with
contextlib
.
closing
(
socket
.
socket
(
socket
.
AF_INET6
if
':'
in
ip
else
socket
.
AF_INET
,
socket
.
SOCK_STREAM
))
as
s
:
try
:
s
.
bind
((
ip
,
port
+
offset
))
except
socket
.
error
:
# Keep compatibility with python2.7
port
=
None
break
except
OSError
:
port
=
None
break
if
port
is
None
:
raise
RuntimeError
(
"Can't find port"
)
return
port
def
retry
(
callback
,
try_count
=
10
,
try_delay
=
0.1
):
"""
...
...
@@ -89,7 +100,7 @@ class ERP5TypeCaucaseTestCase(ERP5TypeTestCase):
if
_ip
is
not
None
:
ip
=
_ip
break
port
=
findFreeTCPPort
(
ip
)
port
=
findFreeTCPPort
Range
(
ip
)
self
.
caucase_runtime
=
caucase_runtime
=
multiprocessing
.
Process
(
target
=
caucase
.
http
.
main
,
kwargs
=
dict
(
...
...
@@ -164,7 +175,7 @@ class ERP5TypeCaucaseTestCase(ERP5TypeTestCase):
# The server fail to start, probably another process
# running in parallel picked the port, so sleep a random
# moment to increase the chance of success
time
.
sleep
(
randint
(
1
,
3
))
time
.
sleep
(
rand
om
.
rand
int
(
1
,
3
))
self
.
_startCaucaseServer
()
self
.
addCleanup
(
self
.
_stopCaucaseServer
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment