##// END OF EJS Templates
tests: make port picker more robust for tests
super-admin -
r4864:deeb4059 default
parent child Browse files
Show More
@@ -21,7 +21,7 b''
21 import json
21 import json
22 import platform
22 import platform
23 import socket
23 import socket
24
24 import random
25 import pytest
25 import pytest
26
26
27 from rhodecode.lib.pyramid_utils import get_app_config
27 from rhodecode.lib.pyramid_utils import get_app_config
@@ -198,17 +198,19 b' def ini_settings(ini_config):'
198 return get_app_config(ini_path)
198 return get_app_config(ini_path)
199
199
200
200
201 def get_available_port():
201 def get_available_port(min_port=40000, max_port=55555):
202 family = socket.AF_INET
202 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
203 socktype = socket.SOCK_STREAM
203 hostname = '127.0.0.1'
204 host = '127.0.0.1'
205
204
206 mysocket = socket.socket(family, socktype)
205 for _ in range(min_port, max_port):
207 mysocket.bind((host, 0))
206 pick_port = random.randint(min_port, max_port)
208 port = mysocket.getsockname()[1]
207 try:
209 mysocket.close()
208 sock.bind((hostname, pick_port))
210 del mysocket
209 sock.close()
211 return port
210 del sock
211 return pick_port
212 except OSError:
213 pass
212
214
213
215
214 @pytest.fixture(scope='session')
216 @pytest.fixture(scope='session')
General Comments 0
You need to be logged in to leave comments. Login now