Skip to content

Commit

Permalink
test_services.py flaky test. (#16518)
Browse files Browse the repository at this point in the history
  • Loading branch information
fchirica committed Oct 17, 2023
1 parent a5f8671 commit 3944028
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
18 changes: 9 additions & 9 deletions chia/simulator/socket.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import secrets
import socket
from contextlib import closing
from typing import Set

recent_ports: Set[int] = set()
Expand All @@ -11,17 +11,17 @@ def find_available_listen_port(name: str = "free") -> int:
global recent_ports

while True:
port = secrets.randbelow(0xFFFF - 1024) + 1024
if port in recent_ports:
continue

with socket.socket() as s:
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
try:
s.bind(("127.0.0.1", port))
s.bind(("", 0))
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
port = s.getsockname()[1]
except OSError:
recent_ports.add(port)
continue

if port in recent_ports:
continue

recent_ports.add(port)
print(f"{name} port: {port}")
return port
return port # type: ignore
Empty file added tests/core/services/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions tests/core/services/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from __future__ import annotations

parallel = False
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ async def test_services_terminate(

try:
result = await client.healthz()
except aiohttp.client_exceptions.ClientConnectorError:
except (
aiohttp.client_exceptions.ClientConnectorError,
aiohttp.client_exceptions.ClientResponseError,
):
pass
else:
if result.get("success", False):
Expand Down

0 comments on commit 3944028

Please sign in to comment.