changeset 596:b1e1c7149a37

new PG upgrades tests
author Alain Mazy <am@osimis.io>
date Thu, 21 Dec 2023 18:02:49 +0100
parents b6c1f0c9ca15
children 0cbefe7369ee
files NewTests/Concurrency/test_concurrency.py NewTests/PostgresUpgrades/__init__.py NewTests/PostgresUpgrades/docker-compose.yml NewTests/PostgresUpgrades/test_pg_upgrades.py NewTests/README
diffstat 4 files changed, 197 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/NewTests/Concurrency/test_concurrency.py	Mon Dec 18 22:27:04 2023 +0100
+++ b/NewTests/Concurrency/test_concurrency.py	Thu Dec 21 18:02:49 2023 +0100
@@ -238,10 +238,11 @@
         self.clear_storage(storage_name=self._storage_name)
 
         start_time = time.time()
+        overall_repeat = 10
 
         for i in range(0, 10):
             workers_count = 5
-            repeat_count = 30
+            repeat_count = 3
 
             # massively upload and delete the same study.  Each worker is writing a part of the instances and deleting them.
             # We are trying to have multiple workers deleting the last instance of a study at the same time.
@@ -263,7 +264,7 @@
             self.assertTrue(self.is_storage_empty(self._storage_name))
 
         elapsed = time.time() - start_time
-        print(f"TIMING test_upload_delete_same_study_from_multiple_threads with {workers_count} workers and {repeat_count}x repeat: {elapsed:.3f} s")
+        print(f"TIMING test_upload_delete_same_study_from_multiple_threads with {workers_count} workers and {repeat_count}x repeat ({overall_repeat}x): {elapsed:.3f} s")
 
 
     # transfers + dicomweb
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NewTests/PostgresUpgrades/docker-compose.yml	Thu Dec 21 18:02:49 2023 +0100
@@ -0,0 +1,88 @@
+version: "3"
+services:
+
+  # Orthanc with PG plugin v2
+  orthanc-pg-15-2:
+    image: osimis/orthanc:18.4.3
+    container_name: orthanc-pg-15-2
+    depends_on: [pg-15]
+    restart: unless-stopped
+    ports: ["8049:8042"]
+    volumes: ["storage-orthanc-pg-15:/var/lib/orthanc/db"]
+    environment:
+      VERBOSE_ENABLED: "true"
+      PG_HOST: "pg-15"
+      PG_LOCK: "false"
+      PG_INDEX_ENABLED: "true"
+      AC_AUTHENTICATION_ENABLED: "false"
+      
+  # Orthanc latest version
+  orthanc-pg-15-under-tests:
+    image: ${ORTHANC_IMAGE_UNDER_TESTS:-osimis/orthanc:latest}
+    container_name: orthanc-pg-15-under-tests
+    depends_on: [pg-15]
+    restart: unless-stopped
+    ports: ["8050:8042"]
+    volumes: ["storage-orthanc-pg-15:/var/lib/orthanc/db"]
+    environment:
+      VERBOSE_ENABLED: "true"
+      ORTHANC__AUTHENTICATION_ENABLED: "false"
+      ORTHANC__POSTGRESQL: |
+        {
+          "Host": "pg-15",
+          "TransactionMode": "READ COMMITTED"
+        }
+
+
+  pg-15:
+    image: postgres:15
+    container_name: pg-15
+    restart: unless-stopped
+    ports: ["5439:5432"]
+    volumes: ["storage-pg-15:/var/lib/postgresql/data"]
+    environment:
+      POSTGRES_HOST_AUTH_METHOD: "trust"
+    healthcheck:
+      test: pg_isready -U postgres -d postgres
+      interval: 1s
+      timeout: 1s
+      retries: 10
+
+
+  # Orthanc latest version
+  orthanc-pg-9-under-tests:
+    image: ${ORTHANC_IMAGE_UNDER_TESTS:-osimis/orthanc:latest}
+    container_name: orthanc-pg-9-under-tests
+    depends_on: [pg-9]
+    restart: unless-stopped
+    ports: ["8051:8042"]
+    volumes: ["storage-orthanc-pg-9:/var/lib/orthanc/db"]
+    environment:
+      VERBOSE_ENABLED: "true"
+      ORTHANC__AUTHENTICATION_ENABLED: "false"
+      ORTHANC__POSTGRESQL: |
+        {
+          "Host": "pg-9",
+          "TransactionMode": "READ COMMITTED"
+        }
+
+
+  pg-9:
+    image: postgres:9.5
+    container_name: pg-9
+    restart: unless-stopped
+    ports: ["5440:5432"]
+    volumes: ["storage-pg-9:/var/lib/postgresql/data"]
+    environment:
+      POSTGRES_HOST_AUTH_METHOD: "trust"
+    healthcheck:
+      test: pg_isready -U postgres -d postgres
+      interval: 1s
+      timeout: 1s
+      retries: 10
+
+volumes:
+  storage-orthanc-pg-15:
+  storage-pg-15:
+  storage-orthanc-pg-9:
+  storage-pg-9:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NewTests/PostgresUpgrades/test_pg_upgrades.py	Thu Dec 21 18:02:49 2023 +0100
@@ -0,0 +1,98 @@
+import subprocess
+import time
+import unittest
+from orthanc_api_client import OrthancApiClient
+from helpers import Helpers
+
+import pathlib
+import os
+here = pathlib.Path(__file__).parent.resolve()
+
+
+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 TestPgUpgrades(unittest.TestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        os.chdir(here)
+        print("Cleaning old compose")
+        subprocess.run(["docker", "compose", "down", "-v", "--remove-orphans"], check=True)
+
+    def test_upgrades_downgrades_with_pg_15(self):
+
+        print("Launching PG-15 server")
+        subprocess.run(["docker", "compose", "up", "pg-15", "-d"], check=True)
+        wait_container_healthy("pg-15")
+
+        print("Launching old Orthanc (PG v2.0)")
+        subprocess.run(["docker", "compose", "up", "orthanc-pg-15-2", "-d"], check=True)
+
+        o = OrthancApiClient("http://localhost:8049")
+        o.wait_started()
+
+        instances = o.upload_folder(here / "../../Database/Knee")
+
+        print("Stopping old Orthanc ")
+        subprocess.run(["docker", "compose", "stop", "orthanc-pg-15-2"], check=True)
+        time.sleep(2)
+
+        print("Launching newest Orthanc")
+        subprocess.run(["docker", "compose", "up", "orthanc-pg-15-under-tests", "-d"], check=True)
+
+        o = OrthancApiClient("http://localhost:8050")
+        o.wait_started()
+
+        # make sure we can 'play' with Orthanc
+        o.instances.get_tags(orthanc_id=instances[0])
+        o.instances.delete_all()
+        instances = o.upload_folder(here / "../../Database/Knee")
+
+        print("Stopping new Orthanc ")
+        subprocess.run(["docker", "compose", "stop", "orthanc-pg-15-under-tests"], check=True)
+        time.sleep(2)
+
+        print("TODO Downgrading Orthanc DB and restart an Orthanc 23.12.1")
+        # ...
+
+    def test_latest_orthanc_with_pg_9(self):
+        print("Launching PG-9 server")
+        subprocess.run(["docker", "compose", "up", "pg-9", "-d"], check=True)
+        wait_container_healthy("pg-9")
+
+        print("Launching newest Orthanc")
+        subprocess.run(
+            ["docker", "compose", "up", "orthanc-pg-9-under-tests", "-d"], 
+            env= {
+                "ORTHANC_IMAGE_UNDER_TESTS": Helpers.orthanc_under_tests_docker_image
+            },
+            check=True)
+
+        o = OrthancApiClient("http://localhost:8051")
+        o.wait_started()
+        instances = o.upload_folder(here / "../../Database/Knee")
+        o.instances.delete(orthanc_ids=instances)
+
+        subprocess.run(["docker", "compose", "down", "-v", "--remove-orphans"], check=True)
--- a/NewTests/README	Mon Dec 18 22:27:04 2023 +0100
+++ b/NewTests/README	Thu Dec 21 18:02:49 2023 +0100
@@ -170,3 +170,11 @@
 python3 NewTests/main.py --pattern=Concurrency.test_concurrency.TestConcurrency.* \
                          --orthanc_under_tests_docker_image=osimis/orthanc:current \
                          --orthanc_under_tests_http_port=8043
+
+PG upgrades:
+-----------
+
+with Docker:
+
+python3 NewTests/main.py --pattern=PostgresUpgrades.test_pg_upgrades.TestPgUpgrades.* \
+                         --orthanc_under_tests_docker_image=osimis/orthanc:current