Skip to content

Commit

Permalink
Update test_supervisor.py
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurimakhija authored Oct 23, 2024
1 parent 874f590 commit 6791557
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions tests/supervisor_test/test_supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,36 @@ def check_container_running(container_name):
shell.run_check("docker inspect --format='{{.NetworkSettings.IPAddress}}' hassio_supervisor")
)

while True:
retries = 0
max_retries = 300 # example: wait for max 300 seconds
while retries < max_retries:
if check_container_running("homeassistant") and check_container_running("hassio_supervisor"):
break
retries += 1
sleep(1)
else:
raise TimeoutError("Containers did not start in time")

try:
if shell_json(f"curl -sSL http://{supervisor_ip}/supervisor/ping").get("result") == "ok":
break
except ExecutionError:
pass # avoid failure when the container is restarting

sleep(1)
MAX_WAIT_TIME = 120 # 2 minutes should be sufficient
+ retries = 0
+ # Wait for containers to start
+ while retries < MAX_WAIT_TIME:
+ if check_container_running("homeassistant") and check_container_running("hassio_supervisor"):
+ break
+ retries += 1
+ sleep(1)
+ else:
+ raise TimeoutError(
+ f"Containers did not start within {MAX_WAIT_TIME} seconds. "
+ "Container status: "
+ f"homeassistant={check_container_running('homeassistant')}, "
+ f"hassio_supervisor={check_container_running('hassio_supervisor')}"
+ )
+
+ # Wait for supervisor ping
+ retries = 0
+ while retries < MAX_WAIT_TIME:
+ try:
+ if shell_json(f"curl -sSL http://{supervisor_ip}/supervisor/ping").get("result") == "ok":
+ break
+ except ExecutionError:
+ pass # avoid failure when the container is restarting
+ retries += 1
+ sleep(1)
+ else:
+ raise TimeoutError(
+ f"Supervisor ping did not respond within {MAX_WAIT_TIME} seconds"
+ )


@pytest.mark.dependency(depends=["test_start_supervisor"])
Expand Down

0 comments on commit 6791557

Please sign in to comment.