Mercurial > hg > orthanc-tests
comparison PerfsDb/TestConfig.py @ 158:df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
author | am@osimis.io |
---|---|
date | Fri, 17 Aug 2018 11:58:26 +0200 |
parents | f1a75985caa8 |
children | 6995d5d12d88 |
comparison
equal
deleted
inserted
replaced
157:ac14100ffbd7 | 158:df1f9946571c |
---|---|
1 import typing | 1 import typing |
2 import subprocess | 2 import subprocess |
3 import os | 3 import os |
4 import shutil | |
4 from orthancRestApi import OrthancClient | 5 from orthancRestApi import OrthancClient |
5 | 6 |
6 from DbSize import DbSize | 7 from DbSize import DbSize |
7 from DbType import DbType | 8 from DbType import DbType |
8 from ConfigFileBuilder import ConfigFileBuilder | 9 from ConfigFileBuilder import ConfigFileBuilder |
43 | 44 |
44 def launchDbServer(self): | 45 def launchDbServer(self): |
45 if self._dbServer is not None: | 46 if self._dbServer is not None: |
46 self._dbServer.launch() | 47 self._dbServer.launch() |
47 | 48 |
48 def launchOrthanc(self, orthancPath): | 49 def launchOrthanc(self, orthancPath) -> bool: |
49 orthanc = OrthancClient("http://127.0.0.1:8042") | 50 orthanc = OrthancClient("http://127.0.0.1:8042") |
50 | 51 |
51 print("Checking if Orthanc is already running") | 52 print("Checking if Orthanc is already running") |
52 if orthanc.isAlive(): | 53 if orthanc.isAlive(): |
53 print("Orthanc is already running") | 54 print("Orthanc is already running") |
54 return | 55 return False |
55 | 56 |
56 print("Launching Orthanc") | 57 print("Launching Orthanc") |
57 self._orthancProcess = subprocess.Popen([ | 58 self._orthancProcess = subprocess.Popen([ |
58 os.path.join(orthancPath, "Orthanc"), | 59 os.path.join(orthancPath, "Orthanc"), |
59 os.path.join("ConfigFiles", self._name + ".json"), | 60 os.path.join(os.path.abspath(os.path.dirname(__file__)), "ConfigFiles", self._name + ".json"), |
60 ]) | 61 ]) |
61 | 62 |
62 print("Waiting for Orthanc to start") | 63 print("Waiting for Orthanc to start") |
63 orthanc.waitStarted(timeout=30) | 64 orthanc.waitStarted(timeout=30) |
64 print("Orthanc has started") | 65 print("Orthanc has started") |
66 return True | |
65 | 67 |
66 def stopOrthanc(self): | 68 def stopOrthanc(self): |
67 if self._orthancProcess is not None: | 69 if self._orthancProcess is not None: |
68 self._orthancProcess.terminate() | 70 self._orthancProcess.terminate() |
69 self._orthancProcess.wait() | 71 self._orthancProcess.wait() |
72 dbPopulator = DbPopulator(orthanc=OrthancClient("http://127.0.0.1:8042"), dbSize=self._dbSize) | 74 dbPopulator = DbPopulator(orthanc=OrthancClient("http://127.0.0.1:8042"), dbSize=self._dbSize) |
73 dbPopulator.populate() | 75 dbPopulator.populate() |
74 | 76 |
75 def runTests(self) -> typing.List[TestResult]: | 77 def runTests(self) -> typing.List[TestResult]: |
76 allTests = [ | 78 allTests = [ |
79 TestStatistics(), | |
77 TestFindStudyByStudyDescription1Result(), | 80 TestFindStudyByStudyDescription1Result(), |
78 TestFindStudyByPatientId1Result(), | 81 TestFindStudyByPatientId1Result(), |
79 TestFindStudyByStudyDescription0Results(), | 82 TestFindStudyByStudyDescription0Results(), |
80 TestFindStudyByPatientId0Results(), | 83 TestFindStudyByPatientId0Results(), |
81 TestFindStudyByPatientId5Results(), | 84 TestFindStudyByPatientId5Results(), |
82 TestUploadFile() | 85 TestUploadFile(), |
83 ] | 86 ] |
84 | 87 |
85 results = [] | 88 results = [] |
86 for test in allTests: | 89 for test in allTests: |
87 test.setOrthancClient(OrthancClient("http://127.0.0.1:8042")) | 90 test.setOrthancClient(OrthancClient("http://127.0.0.1:8042")) |
93 return results | 96 return results |
94 | 97 |
95 def clearDb(self): | 98 def clearDb(self): |
96 if self._dbServer is not None: | 99 if self._dbServer is not None: |
97 self._dbServer.clear() | 100 self._dbServer.clear() |
101 | |
102 # clear storage (in case of Sqlite DB, it will also clear the DB) | |
103 shutil.rmtree(os.path.join(os.path.abspath(os.path.dirname(__file__)), "Storages/{name}".format(name=self._name)), ignore_errors=True) | |
98 | 104 |
99 def generateOrthancConfigurationFile(self, pluginsPath: str): | 105 def generateOrthancConfigurationFile(self, pluginsPath: str): |
100 | 106 |
101 ConfigFileBuilder.generate( | 107 ConfigFileBuilder.generate( |
102 outputPath="ConfigFiles/{name}.json".format(name=self._name), | 108 outputPath=os.path.join(os.path.abspath(os.path.dirname(__file__)), "ConfigFiles/{name}.json".format(name=self._name)), |
103 plugins=[pluginsPath], | 109 pluginsPath=pluginsPath, |
104 storagePath="Storages/{name}".format(name=self._name), | 110 storagePath=os.path.join(os.path.abspath(os.path.dirname(__file__)), "Storages/{name}".format(name=self._name)), |
105 dbType=self._dbType, | 111 dbType=self._dbType, |
106 dbSize=self._dbSize, | 112 dbSize=self._dbSize, |
107 port=self._port | 113 port=self._port |
108 ) | 114 ) |