Mercurial > hg > orthanc-tests
annotate PerfsDb/TestConfig.py @ 160:6995d5d12d88
filtering tests
author | am@osimis.io |
---|---|
date | Fri, 17 Aug 2018 16:17:57 +0200 |
parents | df1f9946571c |
children | 27b3b0df5f90 |
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 | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
45 def launchOrthanc(self, orthancPath) -> 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") | |
54 self._orthancProcess = subprocess.Popen([ | |
55 os.path.join(orthancPath, "Orthanc"), | |
160 | 56 os.path.join(os.path.abspath(os.path.dirname(__file__)), "ConfigFiles", self.label + ".json"), |
156 | 57 ]) |
58 | |
59 print("Waiting for Orthanc to start") | |
60 orthanc.waitStarted(timeout=30) | |
61 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
|
62 return True |
156 | 63 |
64 def stopOrthanc(self): | |
65 if self._orthancProcess is not None: | |
66 self._orthancProcess.terminate() | |
67 self._orthancProcess.wait() | |
68 | |
69 def initializeDb(self): | |
70 dbPopulator = DbPopulator(orthanc=OrthancClient("http://127.0.0.1:8042"), dbSize=self._dbSize) | |
71 dbPopulator.populate() | |
72 | |
160 | 73 def runTests(self, tests: typing.List[Test]) -> typing.List[TestResult]: |
156 | 74 |
75 results = [] | |
160 | 76 for test in tests: |
156 | 77 test.setOrthancClient(OrthancClient("http://127.0.0.1:8042")) |
78 test.setRepeatCount(self._repeatCount) | |
79 result = test.run() | |
80 print(str(result)) | |
81 | |
82 results.append(result) | |
83 return results | |
84 | |
85 def clearDb(self): | |
86 if self._dbServer is not None: | |
87 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
|
88 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
89 # clear storage (in case of Sqlite DB, it will also clear the DB) |
160 | 90 shutil.rmtree(os.path.join(os.path.abspath(os.path.dirname(__file__)), "Storages/{name}".format(name=self.label)), ignore_errors=True) |
156 | 91 |
92 def generateOrthancConfigurationFile(self, pluginsPath: str): | |
93 | |
94 ConfigFileBuilder.generate( | |
160 | 95 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
|
96 pluginsPath=pluginsPath, |
160 | 97 storagePath=os.path.join(os.path.abspath(os.path.dirname(__file__)), "Storages/{name}".format(name=self.label)), |
156 | 98 dbType=self._dbType, |
99 dbSize=self._dbSize, | |
100 port=self._port | |
101 ) |