Skip to content

Commit

Permalink
Tentative to fix flaky up test with AMDA
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>
  • Loading branch information
jeandet committed Jan 15, 2025
1 parent 14e2df6 commit 9ba983d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions speasy/core/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import platform
import re
import time
from functools import partial
from typing import Optional

Expand Down Expand Up @@ -109,7 +110,7 @@ def urlopen(url, timeout: int = DEFAULT_TIMEOUT, headers: dict = None):


def is_server_up(url: Optional[str] = None, host: Optional[str] = None, port: Optional[int] = None,
timeout: int = 5) -> bool:
timeout: int = 5, retries=5) -> bool:
"""Checks if a server is up and running.
Parameters
Expand Down Expand Up @@ -140,11 +141,16 @@ def is_server_up(url: Optional[str] = None, host: Optional[str] = None, port: Op
raise ValueError("Either url or host and port must be provided")
import socket
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(timeout)
result = sock.connect_ex((host, int(port)))
sock.close()
return result == 0
for _ in range(retries):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(timeout)
result = sock.connect_ex((host, int(port)))
sock.close()
if result == 0:
return True
log.debug(f"Server {host}:{port} not up yet, retrying in 1 second")
time.sleep(1.)
return False
except Exception as e:
log.error(f"Error while checking server status: {e}")
return False

0 comments on commit 9ba983d

Please sign in to comment.