Mercurial > hg > orthanc-tests
annotate 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 |
rev | line source |
---|---|
156 | 1 import typing |
2 import subprocess | |
3 import os | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
4 import shutil |
156 | 5 from orthancRestApi import OrthancClient |
6 | |
7 from DbSize import DbSize | |
8 from DbType import DbType | |
9 from ConfigFileBuilder import ConfigFileBuilder | |
10 from DbServer import DbServer | |
11 from DbPopulator import DbPopulator | |
12 from Tests import * | |
13 from TestResult import TestResult | |
14 | |
15 class TestConfig: | |
16 | |
17 def __init__(self, | |
18 label: str, | |
19 dbSize: DbSize, | |
20 dbType: DbType=None, | |
21 dbServer: DbServer=None | |
22 ): | |
23 | |
24 self._dbSize = dbSize | |
25 self._dbServer = dbServer | |
26 self._label = label | |
27 self._port = None | |
28 self._name = "unknown" | |
29 self._orthancProcess = None | |
30 self._repeatCount = 10 | |
31 | |
32 if dbServer is not None: | |
33 self._dbType = dbServer.dbType | |
34 self._dbServer.setLabel(self._label) | |
35 self._port = dbServer.port | |
36 else: | |
37 self._dbType = dbType | |
38 | |
39 def setName(self, name: str): | |
40 self._name = name | |
41 | |
42 def setRepeatCount(self, repeatCount: int): | |
43 self._repeatCount = repeatCount | |
44 | |
45 def launchDbServer(self): | |
46 if self._dbServer is not None: | |
47 self._dbServer.launch() | |
48 | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
49 def launchOrthanc(self, orthancPath) -> bool: |
156 | 50 orthanc = OrthancClient("http://127.0.0.1:8042") |
51 | |
52 print("Checking if Orthanc is already running") | |
53 if orthanc.isAlive(): | |
54 print("Orthanc is already running") | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
55 return False |
156 | 56 |
57 print("Launching Orthanc") | |
58 self._orthancProcess = subprocess.Popen([ | |
59 os.path.join(orthancPath, "Orthanc"), | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
60 os.path.join(os.path.abspath(os.path.dirname(__file__)), "ConfigFiles", self._name + ".json"), |
156 | 61 ]) |
62 | |
63 print("Waiting for Orthanc to start") | |
64 orthanc.waitStarted(timeout=30) | |
65 print("Orthanc has started") | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
66 return True |
156 | 67 |
68 def stopOrthanc(self): | |
69 if self._orthancProcess is not None: | |
70 self._orthancProcess.terminate() | |
71 self._orthancProcess.wait() | |
72 | |
73 def initializeDb(self): | |
74 dbPopulator = DbPopulator(orthanc=OrthancClient("http://127.0.0.1:8042"), dbSize=self._dbSize) | |
75 dbPopulator.populate() | |
76 | |
77 def runTests(self) -> typing.List[TestResult]: | |
78 allTests = [ | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
79 TestStatistics(), |
156 | 80 TestFindStudyByStudyDescription1Result(), |
81 TestFindStudyByPatientId1Result(), | |
82 TestFindStudyByStudyDescription0Results(), | |
83 TestFindStudyByPatientId0Results(), | |
84 TestFindStudyByPatientId5Results(), | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
85 TestUploadFile(), |
156 | 86 ] |
87 | |
88 results = [] | |
89 for test in allTests: | |
90 test.setOrthancClient(OrthancClient("http://127.0.0.1:8042")) | |
91 test.setRepeatCount(self._repeatCount) | |
92 result = test.run() | |
93 print(str(result)) | |
94 | |
95 results.append(result) | |
96 return results | |
97 | |
98 def clearDb(self): | |
99 if self._dbServer is not None: | |
100 self._dbServer.clear() | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
101 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
102 # clear storage (in case of Sqlite DB, it will also clear the DB) |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
103 shutil.rmtree(os.path.join(os.path.abspath(os.path.dirname(__file__)), "Storages/{name}".format(name=self._name)), ignore_errors=True) |
156 | 104 |
105 def generateOrthancConfigurationFile(self, pluginsPath: str): | |
106 | |
107 ConfigFileBuilder.generate( | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
108 outputPath=os.path.join(os.path.abspath(os.path.dirname(__file__)), "ConfigFiles/{name}.json".format(name=self._name)), |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
109 pluginsPath=pluginsPath, |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
110 storagePath=os.path.join(os.path.abspath(os.path.dirname(__file__)), "Storages/{name}".format(name=self._name)), |
156 | 111 dbType=self._dbType, |
112 dbSize=self._dbSize, | |
113 port=self._port | |
114 ) |