Mercurial > hg > orthanc-tests
annotate PerfsDb/TestConfig.py @ 234:93cd4fdd4a67
test_anonymize_relationships_4
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 05 Apr 2019 17:04:37 +0200 |
parents | c92e7191c912 |
children |
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 |
169 | 5 import time |
6 from osimis_timer import TimeOut | |
156 | 7 from orthancRestApi import OrthancClient |
8 | |
9 from DbSize import DbSize | |
10 from DbType import DbType | |
11 from ConfigFileBuilder import ConfigFileBuilder | |
12 from DbServer import DbServer | |
13 from DbPopulator import DbPopulator | |
14 from Tests import * | |
15 from TestResult import TestResult | |
16 | |
17 class TestConfig: | |
18 | |
19 def __init__(self, | |
20 label: str, | |
21 dbSize: DbSize, | |
22 dbType: DbType=None, | |
23 dbServer: DbServer=None | |
24 ): | |
25 | |
26 self._dbSize = dbSize | |
27 self._dbServer = dbServer | |
160 | 28 self.label = label |
156 | 29 self._port = None |
30 self._orthancProcess = None | |
164 | 31 self._repeatCount = 20 |
169 | 32 self._results = [] |
156 | 33 |
34 if dbServer is not None: | |
35 self._dbType = dbServer.dbType | |
160 | 36 self._dbServer.setLabel(self.label) |
156 | 37 self._port = dbServer.port |
38 else: | |
39 self._dbType = dbType | |
40 | |
41 def setRepeatCount(self, repeatCount: int): | |
42 self._repeatCount = repeatCount | |
43 | |
44 def launchDbServer(self): | |
45 if self._dbServer is not None: | |
46 self._dbServer.launch() | |
47 | |
161 | 48 def launchOrthanc(self, orthancPath, verboseEnabled: bool=False, traceEnabled: bool=False) -> bool: |
156 | 49 orthanc = OrthancClient("http://127.0.0.1:8042") |
50 | |
51 print("Checking if Orthanc is already running") | |
52 if orthanc.isAlive(): | |
53 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
|
54 return False |
156 | 55 |
56 print("Launching Orthanc") | |
161 | 57 runOrthancCommand = [ |
156 | 58 os.path.join(orthancPath, "Orthanc"), |
201 | 59 os.path.join(os.path.abspath(os.path.dirname(__file__)), "ConfigFiles", self.label + ".json"), |
60 '--no-jobs', | |
161 | 61 ] |
62 if traceEnabled: | |
63 runOrthancCommand.append("--trace") | |
64 elif verboseEnabled: | |
65 runOrthancCommand.append("--verbose") | |
66 | |
169 | 67 startupTimeResult = TestResult("Startup time") |
68 startTime = time.time() | |
69 | |
161 | 70 self._orthancProcess = subprocess.Popen(runOrthancCommand) |
156 | 71 |
72 print("Waiting for Orthanc to start") | |
170 | 73 if not TimeOut.waitUntilCondition(lambda: orthanc.isAlive(), 5000, evaluateInterval = 0.1): |
169 | 74 print("Orthanc failed to start") |
75 exit(-2) | |
76 endTime = time.time() | |
77 | |
78 startupTimeResult.add((endTime - startTime) * 1000) | |
79 startupTimeResult.compute() | |
80 self._results.append(startupTimeResult) | |
156 | 81 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
|
82 return True |
156 | 83 |
84 def stopOrthanc(self): | |
85 if self._orthancProcess is not None: | |
86 self._orthancProcess.terminate() | |
87 self._orthancProcess.wait() | |
88 | |
89 def initializeDb(self): | |
90 dbPopulator = DbPopulator(orthanc=OrthancClient("http://127.0.0.1:8042"), dbSize=self._dbSize) | |
163 | 91 dbPopulator.populate(self.label) |
156 | 92 |
160 | 93 def runTests(self, tests: typing.List[Test]) -> typing.List[TestResult]: |
156 | 94 |
160 | 95 for test in tests: |
156 | 96 test.setOrthancClient(OrthancClient("http://127.0.0.1:8042")) |
97 test.setRepeatCount(self._repeatCount) | |
98 result = test.run() | |
99 print(str(result)) | |
100 | |
169 | 101 self._results.append(result) |
102 return self._results | |
156 | 103 |
104 def clearDb(self): | |
105 if self._dbServer is not None: | |
106 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
|
107 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
108 # clear storage (in case of Sqlite DB, it will also clear the DB) |
160 | 109 shutil.rmtree(os.path.join(os.path.abspath(os.path.dirname(__file__)), "Storages/{name}".format(name=self.label)), ignore_errors=True) |
156 | 110 |
111 def generateOrthancConfigurationFile(self, pluginsPath: str): | |
112 | |
113 ConfigFileBuilder.generate( | |
160 | 114 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
|
115 pluginsPath=pluginsPath, |
160 | 116 storagePath=os.path.join(os.path.abspath(os.path.dirname(__file__)), "Storages/{name}".format(name=self.label)), |
156 | 117 dbType=self._dbType, |
118 dbSize=self._dbSize, | |
119 port=self._port | |
120 ) |