changeset 162:dbc42a03ee75

more perfs db tests
author am@osimis.io
date Mon, 20 Aug 2018 14:23:54 +0200
parents 27b3b0df5f90
children 53575aa2614b
files PerfsDb/DbPopulator.py PerfsDb/DbServer.py PerfsDb/Run.py PerfsDb/Tests/ToolsFind.py PerfsDb/Tests/UploadFile.py PerfsDb/Tests/__init__.py PerfsDb/requirements.txt
diffstat 7 files changed, 136 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/PerfsDb/DbPopulator.py	Fri Aug 17 17:24:11 2018 +0200
+++ b/PerfsDb/DbPopulator.py	Mon Aug 20 14:23:54 2018 +0200
@@ -67,6 +67,7 @@
 
         # used in TestFindStudyByStudyDescription1Result
         # used in TestFindStudyByPatientId1Result
+        # used in TestToolsFindStudyByStudyInstanceUID
         self.createStudy(studyIndex=99999, patientIndex=99999, seriesCount=1, instancesPerSeries=1)
 
         # then, add data to make the DB "large" or "small"
--- a/PerfsDb/DbServer.py	Fri Aug 17 17:24:11 2018 +0200
+++ b/PerfsDb/DbServer.py	Mon Aug 20 14:23:54 2018 +0200
@@ -8,12 +8,13 @@
 
     class DockerDefinition:
 
-        def __init__(self, image: str, internalPort: int, envVars: typing.Dict[str, str], storagePath: str, command: typing.List[str]=None):
+        def __init__(self, image: str, internalPort: int, envVars: typing.Dict[str, str], storagePath: str, command: typing.List[str]=None, extraInitTime: int=0):
             self.image = image
             self.internalPort = internalPort
             self.envVars = envVars
             self.storagePath = storagePath
             self.command = command
+            self.extraInitTime = extraInitTime
 
     def __init__(self, dbType: DbType, port: int):
 
@@ -34,6 +35,15 @@
         ])            
         return ret == 0
 
+    def volumeExists(self) -> bool:
+        ret = subprocess.call([
+            "docker",
+            "volume",
+            "inspect",
+            self._label
+        ])
+        return ret == 0
+
     def launch(self):
         dockerDefinition = self.getDockerDefinition()
 
@@ -42,13 +52,15 @@
             print("DbServer is already running")
             return
 
-        # create a volume (if it already exists, it wont be modified)
-        subprocess.check_call([
-            "docker", 
-            "volume", 
-            "create", 
-            "--name=" + self._label
-        ])
+        volumeCreatedThisTime = False
+        if not self.volumeExists():
+            subprocess.check_call([
+                "docker", 
+                "volume", 
+                "create", 
+                "--name=" + self._label
+            ])
+            volumeCreatedThisTime = True
         
         dockerRunCommand = [
             "docker",
@@ -87,6 +99,9 @@
             print("DbServer still not ready after 30 sec")
             raise TimeoutError
 
+        if dockerDefinition.extraInitTime > 0 and volumeCreatedThisTime:
+            time.sleep(dockerDefinition.extraInitTime)
+
     def stop(self):
         if self.isRunning():
             subprocess.check_call([
@@ -124,7 +139,8 @@
                     "MYSQL_ROOT_PASSWORD": "foo-root"       
                 },
                 storagePath="/var/lib/mysql",
-                command=["mysqld", "--default-authentication-plugin=mysql_native_password", "--log-bin-trust-function-creators=1"]
+                command=["mysqld", "--default-authentication-plugin=mysql_native_password", "--log-bin-trust-function-creators=1"],
+                extraInitTime=30
             )
         elif self.dbType == DbType.MSSQL:
             return DbServer.DockerDefinition(
@@ -134,7 +150,8 @@
                     "ACCEPT_EULA": "Y",
                     "SA_PASSWORD": "MyStrOngPa55word!"
                 },
-                storagePath="/var/opt/mssql/data"
+                storagePath="/var/opt/mssql/data",
+                extraInitTime=10
             )
         elif self.dbType == DbType.PG9 or self.dbType == DbType.PG10 or self.dbType == DbType.PG11:
             if self.dbType == DbType.PG9:
--- a/PerfsDb/Run.py	Fri Aug 17 17:24:11 2018 +0200
+++ b/PerfsDb/Run.py	Mon Aug 20 14:23:54 2018 +0200
@@ -52,6 +52,9 @@
     TestFindStudyByPatientId5Results(),
     TestUploadNextPatientFile(),
     TestUploadFirstPatientFile(),
+    TestUploadLargeFile10MB(),
+    TestToolsFindStudyByStudyInstanceUID(),
+    TestToolsFindPatientByPatientID()
 ]
 
 selectedTestConfigs = []
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PerfsDb/Tests/ToolsFind.py	Mon Aug 20 14:23:54 2018 +0200
@@ -0,0 +1,21 @@
+from Test import Test
+
+class TestToolsFindStudyByStudyInstanceUID(Test):
+
+    def __init__(self, name:str = "ToolsFindStudyByStudyInstanceUID"):
+        super().__init__(name)
+
+    def test(self):
+        self._orthanc.studies.find(
+            studyInstanceUid="99999.99999"
+        )
+
+class TestToolsFindPatientByPatientID(Test):
+
+    def __init__(self, name:str = "ToolsFindPatientByPatientID"):
+        super().__init__(name)
+
+    def test(self):
+        self._orthanc.patients.find(
+            dicomPatientId="99999"
+        )
\ No newline at end of file
--- a/PerfsDb/Tests/UploadFile.py	Fri Aug 17 17:24:11 2018 +0200
+++ b/PerfsDb/Tests/UploadFile.py	Mon Aug 20 14:23:54 2018 +0200
@@ -1,5 +1,11 @@
+import json
+import tempfile
+import base64
+from PIL import Image
+
 from Test import Test
 
+
 class TestUploadFirstPatientFile(Test):
 
     def __init__(self, name:str = "UploadFirstPatientFile", filePath:str = "../Database/DummyCT.dcm"):
@@ -37,6 +43,11 @@
         # upload a source file that we will modify
         self._sourceInstanceId = self._orthanc.uploadDicomFile(self._filePath)
         
+        # make sure no file is already in Orthanc before the upload
+        patient = self._orthanc.patients.find("UploadNextPatientFile")
+        if patient is not None:
+            self._orthanc.patients.delete(patient.id)
+
         # upload the first instance of this patient
         self._dicomFileContent = self._modifyFile()
         self._orthanc.uploadDicom(self._dicomFileContent)
@@ -73,4 +84,72 @@
                 "InstanceNumber": str(self._instanceIndex)
             },
             deleteOriginal=False
-        )
\ No newline at end of file
+        )
+
+
+
+class TestUploadLargeFile10MB(Test):
+
+    def __init__(self, name:str = "UploadLargeFile10MB"):
+        super().__init__(name)
+        self._instanceId = None
+        self._dicomFileContent = None
+        self._instanceIndex = 0
+
+    def beforeAll(self):
+        self._clear()
+
+        # make sure no file is already in Orthanc before the upload
+        patient = self._orthanc.patients.find("UploadLargeFile")
+        if patient is not None:
+            self._orthanc.patients.delete(patient.id)
+
+        # upload a source file that we will modify
+        self._sourceInstanceId = self._orthanc.post(
+            relativeUrl="tools/create-dicom",
+            data=json.dumps({
+                "Tags": {
+                    'PatientName' : 'UploadLargeFile',
+                    'PatientID' : 'UploadLargeFile',
+                    '8899-8899' : 'data:application/octet-stream;base64,' + base64.b64encode(b"\0" * 10000000).decode('utf-8')
+                }
+            })
+        ).json()["ID"]
+
+        # upload the first instance of this patient
+        self._dicomFileContent = self._modifyFile()
+        self._orthanc.uploadDicom(self._dicomFileContent)
+
+
+
+    def beforeEach(self):
+        self._dicomFileContent = self._modifyFile()
+
+    def test(self):
+        self._orthanc.uploadDicom(self._dicomFileContent)
+
+    def afterAll(self):
+        self._clear()
+
+    def _clear(self):
+        patient = self._orthanc.patients.find("UploadLargeFile")
+        if patient is not None:
+            self._orthanc.patients.delete(patient.id)
+
+    def _modifyFile(self):
+        self._instanceIndex += 1
+        return self._orthanc.instances.modify(
+            instanceId=self._sourceInstanceId,
+            replaceTags={
+                "PatientName": "UploadLargeFile",
+                "PatientID": "UploadLargeFile",
+                "StudyDescription": "UploadLargeFile",
+                "SeriesDescription": "UploadLargeFile",
+                "SOPInstanceUID": "999998.888888.777777.666666.555555.44444",
+                "StudyInstanceUID": "999998.888888.777777.666666",
+                "SeriesInstanceUID": "999998.888888.777777.666666.555555",
+                "SeriesNumber": "1",
+                "InstanceNumber": str(self._instanceIndex)
+            },
+            deleteOriginal=False
+        )
--- a/PerfsDb/Tests/__init__.py	Fri Aug 17 17:24:11 2018 +0200
+++ b/PerfsDb/Tests/__init__.py	Mon Aug 20 14:23:54 2018 +0200
@@ -1,3 +1,4 @@
 from .UploadFile import *
 from .FindStudy import *
-from .Statistics import *
\ No newline at end of file
+from .Statistics import *
+from .ToolsFind import *
\ No newline at end of file
--- a/PerfsDb/requirements.txt	Fri Aug 17 17:24:11 2018 +0200
+++ b/PerfsDb/requirements.txt	Mon Aug 20 14:23:54 2018 +0200
@@ -1,1 +1,2 @@
-http://orthanc.osimis.io/pythonToolbox/OsimisToolbox-22.0.0.tar.gz
\ No newline at end of file
+http://orthanc.osimis.io/pythonToolbox/OsimisToolbox-22.0.0.tar.gz
+pillow
\ No newline at end of file