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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
1 import typing
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
2 import subprocess
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
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
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
5 from orthancRestApi import OrthancClient
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
6
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
7 from DbSize import DbSize
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
8 from DbType import DbType
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
9 from ConfigFileBuilder import ConfigFileBuilder
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
10 from DbServer import DbServer
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
11 from DbPopulator import DbPopulator
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
12 from Tests import *
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
13 from TestResult import TestResult
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
14
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
15 class TestConfig:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
16
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
17 def __init__(self,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
18 label: str,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
19 dbSize: DbSize,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
20 dbType: DbType=None,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
21 dbServer: DbServer=None
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
22 ):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
23
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
24 self._dbSize = dbSize
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
25 self._dbServer = dbServer
160
6995d5d12d88 filtering tests
am@osimis.io
parents: 158
diff changeset
26 self.label = label
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
27 self._port = None
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
28 self._orthancProcess = None
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
29 self._repeatCount = 10
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
30
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
31 if dbServer is not None:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
32 self._dbType = dbServer.dbType
160
6995d5d12d88 filtering tests
am@osimis.io
parents: 158
diff changeset
33 self._dbServer.setLabel(self.label)
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
34 self._port = dbServer.port
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
35 else:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
36 self._dbType = dbType
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
37
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
38 def setRepeatCount(self, repeatCount: int):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
39 self._repeatCount = repeatCount
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
40
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
41 def launchDbServer(self):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
42 if self._dbServer is not None:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
43 self._dbServer.launch()
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
44
161
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 160
diff changeset
45 def launchOrthanc(self, orthancPath, verboseEnabled: bool=False, traceEnabled: bool=False) -> bool:
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
46 orthanc = OrthancClient("http://127.0.0.1:8042")
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
47
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
48 print("Checking if Orthanc is already running")
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
49 if orthanc.isAlive():
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
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
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
52
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
53 print("Launching Orthanc")
161
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 160
diff changeset
54 runOrthancCommand = [
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
55 os.path.join(orthancPath, "Orthanc"),
160
6995d5d12d88 filtering tests
am@osimis.io
parents: 158
diff changeset
56 os.path.join(os.path.abspath(os.path.dirname(__file__)), "ConfigFiles", self.label + ".json"),
161
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 160
diff changeset
57 ]
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 160
diff changeset
58 if traceEnabled:
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 160
diff changeset
59 runOrthancCommand.append("--trace")
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 160
diff changeset
60 elif verboseEnabled:
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 160
diff changeset
61 runOrthancCommand.append("--verbose")
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 160
diff changeset
62
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 160
diff changeset
63 self._orthancProcess = subprocess.Popen(runOrthancCommand)
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
64
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
65 print("Waiting for Orthanc to start")
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
66 orthanc.waitStarted(timeout=30)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
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
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
69
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
70 def stopOrthanc(self):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
71 if self._orthancProcess is not None:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
72 self._orthancProcess.terminate()
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
73 self._orthancProcess.wait()
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
74
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
75 def initializeDb(self):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
76 dbPopulator = DbPopulator(orthanc=OrthancClient("http://127.0.0.1:8042"), dbSize=self._dbSize)
163
53575aa2614b added stats during db creation
am@osimis.io
parents: 161
diff changeset
77 dbPopulator.populate(self.label)
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
78
160
6995d5d12d88 filtering tests
am@osimis.io
parents: 158
diff changeset
79 def runTests(self, tests: typing.List[Test]) -> typing.List[TestResult]:
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
80
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
81 results = []
160
6995d5d12d88 filtering tests
am@osimis.io
parents: 158
diff changeset
82 for test in tests:
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
83 test.setOrthancClient(OrthancClient("http://127.0.0.1:8042"))
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
84 test.setRepeatCount(self._repeatCount)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
85 result = test.run()
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
86 print(str(result))
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
87
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
88 results.append(result)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
89 return results
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
90
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
91 def clearDb(self):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
92 if self._dbServer is not None:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
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
6995d5d12d88 filtering tests
am@osimis.io
parents: 158
diff changeset
96 shutil.rmtree(os.path.join(os.path.abspath(os.path.dirname(__file__)), "Storages/{name}".format(name=self.label)), ignore_errors=True)
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
97
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
98 def generateOrthancConfigurationFile(self, pluginsPath: str):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
99
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
100 ConfigFileBuilder.generate(
160
6995d5d12d88 filtering tests
am@osimis.io
parents: 158
diff changeset
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
6995d5d12d88 filtering tests
am@osimis.io
parents: 158
diff changeset
103 storagePath=os.path.join(os.path.abspath(os.path.dirname(__file__)), "Storages/{name}".format(name=self.label)),
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
104 dbType=self._dbType,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
105 dbSize=self._dbSize,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
106 port=self._port
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
107 )