Show More
@@ -158,18 +158,8 b' class HttpHooksCallbackDaemon(ThreadedHo' | |||||
158 | return socket.gethostname() or '127.0.0.1' |
|
158 | return socket.gethostname() or '127.0.0.1' | |
159 |
|
159 | |||
160 | def get_available_port(self, min_port=20000, max_port=65535): |
|
160 | def get_available_port(self, min_port=20000, max_port=65535): | |
161 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
161 | from rhodecode.lib.utils2 import get_available_port as _get_port | |
162 | hostname = self.get_hostname() |
|
162 | return _get_port(min_port, max_port) | |
163 |
|
||||
164 | for _ in range(min_port, max_port): |
|
|||
165 | pick_port = random.randint(min_port, max_port) |
|
|||
166 | try: |
|
|||
167 | sock.bind((hostname, pick_port)) |
|
|||
168 | sock.close() |
|
|||
169 | del sock |
|
|||
170 | return pick_port |
|
|||
171 | except OSError: |
|
|||
172 | pass |
|
|||
173 |
|
163 | |||
174 | def _prepare(self, txn_id=None, host=None, port=None): |
|
164 | def _prepare(self, txn_id=None, host=None, port=None): | |
175 | if not host or host == "*": |
|
165 | if not host or host == "*": |
@@ -35,6 +35,8 b' import urllib' | |||||
35 | import urlobject |
|
35 | import urlobject | |
36 | import uuid |
|
36 | import uuid | |
37 | import getpass |
|
37 | import getpass | |
|
38 | import socket | |||
|
39 | import random | |||
38 | from functools import update_wrapper, partial, wraps |
|
40 | from functools import update_wrapper, partial, wraps | |
39 |
|
41 | |||
40 | import pygments.lexers |
|
42 | import pygments.lexers | |
@@ -1171,3 +1173,21 b' def user_agent_normalizer(user_agent_raw' | |||||
1171 | raise |
|
1173 | raise | |
1172 |
|
1174 | |||
1173 | return ua |
|
1175 | return ua | |
|
1176 | ||||
|
1177 | ||||
|
1178 | def get_available_port(min_port=40000, max_port=55555): | |||
|
1179 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |||
|
1180 | hostname = '127.0.0.1' | |||
|
1181 | pick_port = min_port | |||
|
1182 | ||||
|
1183 | for _ in range(min_port, max_port): | |||
|
1184 | pick_port = random.randint(min_port, max_port) | |||
|
1185 | try: | |||
|
1186 | sock.bind((hostname, pick_port)) | |||
|
1187 | sock.close() | |||
|
1188 | break | |||
|
1189 | except OSError: | |||
|
1190 | pass | |||
|
1191 | ||||
|
1192 | del sock | |||
|
1193 | return pick_port |
@@ -199,18 +199,8 b' def ini_settings(ini_config):' | |||||
199 |
|
199 | |||
200 |
|
200 | |||
201 | def get_available_port(min_port=40000, max_port=55555): |
|
201 | def get_available_port(min_port=40000, max_port=55555): | |
202 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
202 | from rhodecode.lib.utils2 import get_available_port as _get_port | |
203 | hostname = '127.0.0.1' |
|
203 | return _get_port(min_port, max_port) | |
204 |
|
||||
205 | for _ in range(min_port, max_port): |
|
|||
206 | pick_port = random.randint(min_port, max_port) |
|
|||
207 | try: |
|
|||
208 | sock.bind((hostname, pick_port)) |
|
|||
209 | sock.close() |
|
|||
210 | del sock |
|
|||
211 | return pick_port |
|
|||
212 | except OSError: |
|
|||
213 | pass |
|
|||
214 |
|
204 | |||
215 |
|
205 | |||
216 | @pytest.fixture(scope='session') |
|
206 | @pytest.fixture(scope='session') |
General Comments 0
You need to be logged in to leave comments.
Login now