diff NewTests/helpers.py @ 601:3e15e950c462

new transfer tests in the concurrency section
author Alain Mazy <am@osimis.io>
date Fri, 19 Jan 2024 15:03:47 +0100
parents f4f0e2d24a51
children 4b3d13e498a5
line wrap: on
line diff
--- a/NewTests/helpers.py	Fri Jan 19 09:15:57 2024 +0100
+++ b/NewTests/helpers.py	Fri Jan 19 15:03:47 2024 +0100
@@ -6,6 +6,7 @@
 import typing
 import shutil
 import glob
+import time
 from threading import Thread
 
 
@@ -19,6 +20,32 @@
 }
 
 
+def get_container_health(container_name):
+    try:
+        # Run the docker inspect command
+        result = subprocess.run(
+            ["docker", "inspect", "--format", "{{.State.Health.Status}}", container_name],
+            capture_output=True,
+            text=True,
+            check=True,
+        )
+        
+        # Extract the health status from the command output
+        return result.stdout.strip()
+
+    except subprocess.CalledProcessError as e:
+        print(f"Error checking container health: {e}")
+        return None
+
+def wait_container_healthy(container_name):
+    retry = 0
+
+    while (get_container_health(container_name) != "healthy" and retry < 200):
+        print(f"Waiting for {container_name} to be healty")
+        time.sleep(1)
+
+
+
 class Helpers:
 
     orthanc_under_tests_hostname: str = 'localhost'