Skip to content

Commit a8c5ae0

Browse files
authored
Don't try to use a fixed port in test_server_config_default (#8272)
We had a flake regarding this. (At least on my machine?), linux never randomly assigns an even numbered port, so probably the flake collided with something external specifically looking for it? The find_available_port mechanism is fundamentally racy, of course; the port could be allocated by someone else immediately, and in testing I did manage to observe cycle lengths as short as 2 before a reuse. Possibly these tests should just have a big hammer `@retry_failed_test(3)` decorator around them or something, but I am reluctant to introduce this because I fear we will use it instead of writing proper tests. (Most tests don't have as good an excuse for flakiness as needing to allocate a shared resource in a 16-bit namespace).
1 parent 0676b5e commit a8c5ae0

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

edb/testbase/server.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3002,23 +3002,10 @@ def get_cases_by_shard(cases, selected_shard, total_shards, verbosity, stats):
30023002
return _merge_results(cases)
30033003

30043004

3005-
def find_available_port(max_value=None) -> int:
3006-
if max_value is None:
3007-
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
3008-
sock.bind(("localhost", 0))
3009-
return sock.getsockname()[1]
3010-
elif max_value > 1024:
3011-
port = max_value
3012-
while port > 1024:
3013-
try:
3014-
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
3015-
sock.bind(("localhost", port))
3016-
return port
3017-
except IOError:
3018-
port -= 1
3019-
raise RuntimeError("cannot find an available port")
3020-
else:
3021-
raise ValueError("max_value must be greater than 1024")
3005+
def find_available_port() -> int:
3006+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
3007+
sock.bind(("localhost", 0))
3008+
return sock.getsockname()[1]
30223009

30233010

30243011
def _needs_factoring(weakly):

tests/test_server_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,7 +2366,7 @@ async def test_server_config_env_03(self):
23662366
"cannot use CONFIGURE INSTANCE in multi-tenant mode",
23672367
)
23682368
async def test_server_config_default(self):
2369-
p1 = tb.find_available_port(max_value=50000)
2369+
p1 = tb.find_available_port()
23702370
async with tb.start_edgedb_server(
23712371
extra_args=["--port", str(p1)]
23722372
) as sd:
@@ -2378,7 +2378,7 @@ async def test_server_config_default(self):
23782378
"""),
23792379
p1,
23802380
)
2381-
p2 = tb.find_available_port(p1 - 1)
2381+
p2 = tb.find_available_port()
23822382
await conn.execute(f"""\
23832383
configure instance set listen_port := {p2}
23842384
""")

0 commit comments

Comments
 (0)