Mercurial > hg > orthanc-tests
annotate PerfsDb/TestConfig.py @ 178:c896ac762b9f
Added tag Orthanc-1.4.2 for changeset ef6b791c6d62
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 20 Sep 2018 14:22:38 +0200 |
parents | a38c3cbc74dd |
children | c92e7191c912 |
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"), |
160 | 59 os.path.join(os.path.abspath(os.path.dirname(__file__)), "ConfigFiles", self.label + ".json"), |
161 | 60 ] |
61 if traceEnabled: | |
62 runOrthancCommand.append("--trace") | |
63 elif verboseEnabled: | |
64 runOrthancCommand.append("--verbose") | |
65 | |
169 | 66 startupTimeResult = TestResult("Startup time") |
67 startTime = time.time() | |
68 | |
161 | 69 self._orthancProcess = subprocess.Popen(runOrthancCommand) |
156 | 70 |
71 print("Waiting for Orthanc to start") | |
170 | 72 if not TimeOut.waitUntilCondition(lambda: orthanc.isAlive(), 5000, evaluateInterval = 0.1): |
169 | 73 print("Orthanc failed to start") |
74 exit(-2) | |
75 endTime = time.time() | |
76 | |
77 startupTimeResult.add((endTime - startTime) * 1000) | |
78 startupTimeResult.compute() | |
79 self._results.append(startupTimeResult) | |
156 | 80 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
|
81 return True |
156 | 82 |
83 def stopOrthanc(self): | |
84 if self._orthancProcess is not None: | |
85 self._orthancProcess.terminate() | |
86 self._orthancProcess.wait() | |
87 | |
88 def initializeDb(self): | |
89 dbPopulator = DbPopulator(orthanc=OrthancClient("http://127.0.0.1:8042"), dbSize=self._dbSize) | |
163 | 90 dbPopulator.populate(self.label) |
156 | 91 |
160 | 92 def runTests(self, tests: typing.List[Test]) -> typing.List[TestResult]: |
156 | 93 |
160 | 94 for test in tests: |
156 | 95 test.setOrthancClient(OrthancClient("http://127.0.0.1:8042")) |
96 test.setRepeatCount(self._repeatCount) | |
97 result = test.run() | |
98 print(str(result)) | |
99 | |
169 | 100 self._results.append(result) |
101 return self._results | |
156 | 102 |
103 def clearDb(self): | |
104 if self._dbServer is not None: | |
105 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
|
106 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
107 # clear storage (in case of Sqlite DB, it will also clear the DB) |
160 | 108 shutil.rmtree(os.path.join(os.path.abspath(os.path.dirname(__file__)), "Storages/{name}".format(name=self.label)), ignore_errors=True) |
156 | 109 |
110 def generateOrthancConfigurationFile(self, pluginsPath: str): | |
111 | |
112 ConfigFileBuilder.generate( | |
160 | 113 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
|
114 pluginsPath=pluginsPath, |
160 | 115 storagePath=os.path.join(os.path.abspath(os.path.dirname(__file__)), "Storages/{name}".format(name=self.label)), |
156 | 116 dbType=self._dbType, |
117 dbSize=self._dbSize, | |
118 port=self._port | |
119 ) |