Mercurial > hg > orthanc-tests
annotate PerfsDb/TestConfig.py @ 163:53575aa2614b
added stats during db creation
author | am@osimis.io |
---|---|
date | Mon, 20 Aug 2018 14:54:32 +0200 |
parents | 27b3b0df5f90 |
children | ff939d07989f |
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 | |
160 | 26 self.label = label |
156 | 27 self._port = None |
28 self._orthancProcess = None | |
29 self._repeatCount = 10 | |
30 | |
31 if dbServer is not None: | |
32 self._dbType = dbServer.dbType | |
160 | 33 self._dbServer.setLabel(self.label) |
156 | 34 self._port = dbServer.port |
35 else: | |
36 self._dbType = dbType | |
37 | |
38 def setRepeatCount(self, repeatCount: int): | |
39 self._repeatCount = repeatCount | |
40 | |
41 def launchDbServer(self): | |
42 if self._dbServer is not None: | |
43 self._dbServer.launch() | |
44 | |
161 | 45 def launchOrthanc(self, orthancPath, verboseEnabled: bool=False, traceEnabled: bool=False) -> bool: |
156 | 46 orthanc = OrthancClient("http://127.0.0.1:8042") |
47 | |
48 print("Checking if Orthanc is already running") | |
49 if orthanc.isAlive(): | |
50 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
|
51 return False |
156 | 52 |
53 print("Launching Orthanc") | |
161 | 54 runOrthancCommand = [ |
156 | 55 os.path.join(orthancPath, "Orthanc"), |
160 | 56 os.path.join(os.path.abspath(os.path.dirname(__file__)), "ConfigFiles", self.label + ".json"), |
161 | 57 ] |
58 if traceEnabled: | |
59 runOrthancCommand.append("--trace") | |
60 elif verboseEnabled: | |
61 runOrthancCommand.append("--verbose") | |
62 | |
63 self._orthancProcess = subprocess.Popen(runOrthancCommand) | |
156 | 64 |
65 print("Waiting for Orthanc to start") | |
66 orthanc.waitStarted(timeout=30) | |
67 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
|
68 return True |
156 | 69 |
70 def stopOrthanc(self): | |
71 if self._orthancProcess is not None: | |
72 self._orthancProcess.terminate() | |
73 self._orthancProcess.wait() | |
74 | |
75 def initializeDb(self): | |
76 dbPopulator = DbPopulator(orthanc=OrthancClient("http://127.0.0.1:8042"), dbSize=self._dbSize) | |
163 | 77 dbPopulator.populate(self.label) |
156 | 78 |
160 | 79 def runTests(self, tests: typing.List[Test]) -> typing.List[TestResult]: |
156 | 80 |
81 results = [] | |
160 | 82 for test in tests: |
156 | 83 test.setOrthancClient(OrthancClient("http://127.0.0.1:8042")) |
84 test.setRepeatCount(self._repeatCount) | |
85 result = test.run() | |
86 print(str(result)) | |
87 | |
88 results.append(result) | |
89 return results | |
90 | |
91 def clearDb(self): | |
92 if self._dbServer is not None: | |
93 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
|
94 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
95 # clear storage (in case of Sqlite DB, it will also clear the DB) |
160 | 96 shutil.rmtree(os.path.join(os.path.abspath(os.path.dirname(__file__)), "Storages/{name}".format(name=self.label)), ignore_errors=True) |
156 | 97 |
98 def generateOrthancConfigurationFile(self, pluginsPath: str): | |
99 | |
100 ConfigFileBuilder.generate( | |
160 | 101 outputPath=os.path.join(os.path.abspath(os.path.dirname(__file__)), "ConfigFiles/{name}.json".format(name=self.label)), |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
102 pluginsPath=pluginsPath, |
160 | 103 storagePath=os.path.join(os.path.abspath(os.path.dirname(__file__)), "Storages/{name}".format(name=self.label)), |
156 | 104 dbType=self._dbType, |
105 dbSize=self._dbSize, | |
106 port=self._port | |
107 ) |