|
3 | 3 | import sys
|
4 | 4 | import collections
|
5 | 5 | import signal
|
6 |
| -import random |
7 | 6 | import fcntl
|
8 | 7 | import difflib
|
9 | 8 | import time
|
10 | 9 | import json
|
11 | 10 | import subprocess
|
12 |
| -from gevent import socket |
13 | 11 | from lib.colorer import color_stdout
|
14 | 12 |
|
15 | 13 | try:
|
@@ -85,63 +83,6 @@ def print_tail_n(filename, num_lines=None):
|
85 | 83 | color_stdout(line, schema='tail')
|
86 | 84 |
|
87 | 85 |
|
88 |
| -def check_port(port, rais=True, ipv4=True, ipv6=True): |
89 |
| - """ True -- it's possible to listen on this port for TCP/IPv4 or TCP/IPv6 |
90 |
| - connections (UNIX Sockets in case of file path). False -- otherwise. |
91 |
| - """ |
92 |
| - try: |
93 |
| - if isinstance(port, integer_types): |
94 |
| - if ipv4: |
95 |
| - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
96 |
| - sock.bind(('127.0.0.1', port)) |
97 |
| - sock.listen(5) |
98 |
| - sock.close() |
99 |
| - if ipv6: |
100 |
| - sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) |
101 |
| - sock.bind(('::1', port)) |
102 |
| - sock.listen(5) |
103 |
| - sock.close() |
104 |
| - else: |
105 |
| - sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
106 |
| - sock.connect(port) |
107 |
| - except socket.error: |
108 |
| - if rais: |
109 |
| - raise RuntimeError( |
110 |
| - "The server is already running on port {0}".format(port)) |
111 |
| - return False |
112 |
| - return True |
113 |
| - |
114 |
| - |
115 |
| -# A list of ports used so far. Avoid reusing ports |
116 |
| -# to reduce race conditions between starting and stopping servers. |
117 |
| -# We're using tarantoolctl for instance control, and it reports |
118 |
| -# a successful stop of the server before it really closes its |
119 |
| -# network sockets |
120 |
| -ports = {} |
121 |
| - |
122 |
| - |
123 |
| -is_ipv6_supported = check_port(port=0, rais=False, ipv4=False, ipv6=True) |
124 |
| - |
125 |
| - |
126 |
| -def find_port(): |
127 |
| - global ports |
128 |
| - start_port = int(os.environ.get('TEST_RUN_TCP_PORT_START', '3000')) |
129 |
| - end_port = int(os.environ.get('TEST_RUN_TCP_PORT_END', '65535')) |
130 |
| - port = random.randrange(start_port, end_port + 1) |
131 |
| - |
132 |
| - while port <= end_port: |
133 |
| - is_free = check_port(port, False, ipv4=True, ipv6=is_ipv6_supported) |
134 |
| - if port not in ports and is_free: |
135 |
| - ports[port] = True |
136 |
| - return port |
137 |
| - port += 1 |
138 |
| - |
139 |
| - # We've made a full circle, clear the list of used ports and start |
140 |
| - # from scratch |
141 |
| - ports = {} |
142 |
| - return find_port() |
143 |
| - |
144 |
| - |
145 | 86 | def find_in_path(name):
|
146 | 87 | path = os.curdir + os.pathsep + os.environ["PATH"]
|
147 | 88 | for _dir in path.split(os.pathsep):
|
|
0 commit comments