annotate PerfsDb/TestConfig.py @ 651:c3aa39672db1

fix path
author Alain Mazy <am@orthanc.team>
date Mon, 03 Jun 2024 14:20:17 +0200
parents c92e7191c912
children
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
169
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 164
diff changeset
5 import time
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 164
diff changeset
6 from osimis_timer import TimeOut
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
7 from orthancRestApi import OrthancClient
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
8
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
9 from DbSize import DbSize
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
10 from DbType import DbType
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
11 from ConfigFileBuilder import ConfigFileBuilder
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
12 from DbServer import DbServer
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
13 from DbPopulator import DbPopulator
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
14 from Tests import *
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
15 from TestResult import TestResult
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 class TestConfig:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
18
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
19 def __init__(self,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
20 label: str,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
21 dbSize: DbSize,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
22 dbType: DbType=None,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
23 dbServer: DbServer=None
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
24 ):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
25
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
26 self._dbSize = dbSize
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
27 self._dbServer = dbServer
160
6995d5d12d88 filtering tests
am@osimis.io
parents: 158
diff changeset
28 self.label = label
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
29 self._port = None
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
30 self._orthancProcess = None
164
ff939d07989f saving results
am@osimis.io
parents: 163
diff changeset
31 self._repeatCount = 20
169
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 164
diff changeset
32 self._results = []
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
33
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
34 if dbServer is not None:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
35 self._dbType = dbServer.dbType
160
6995d5d12d88 filtering tests
am@osimis.io
parents: 158
diff changeset
36 self._dbServer.setLabel(self.label)
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
37 self._port = dbServer.port
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
38 else:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
39 self._dbType = dbType
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 setRepeatCount(self, repeatCount: int):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
42 self._repeatCount = repeatCount
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
43
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
44 def launchDbServer(self):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
45 if self._dbServer is not None:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
46 self._dbServer.launch()
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
47
161
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 160
diff changeset
48 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
49 orthanc = OrthancClient("http://127.0.0.1:8042")
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
50
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
51 print("Checking if Orthanc is already running")
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
52 if orthanc.isAlive():
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
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
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
55
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
56 print("Launching Orthanc")
161
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 160
diff changeset
57 runOrthancCommand = [
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
58 os.path.join(orthancPath, "Orthanc"),
201
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 170
diff changeset
59 os.path.join(os.path.abspath(os.path.dirname(__file__)), "ConfigFiles", self.label + ".json"),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 170
diff changeset
60 '--no-jobs',
161
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 160
diff changeset
61 ]
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 160
diff changeset
62 if traceEnabled:
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 160
diff changeset
63 runOrthancCommand.append("--trace")
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 160
diff changeset
64 elif verboseEnabled:
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 160
diff changeset
65 runOrthancCommand.append("--verbose")
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 160
diff changeset
66
169
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 164
diff changeset
67 startupTimeResult = TestResult("Startup time")
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 164
diff changeset
68 startTime = time.time()
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 164
diff changeset
69
161
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 160
diff changeset
70 self._orthancProcess = subprocess.Popen(runOrthancCommand)
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
71
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
72 print("Waiting for Orthanc to start")
170
a38c3cbc74dd increasedd startup timeout
am@osimis.io
parents: 169
diff changeset
73 if not TimeOut.waitUntilCondition(lambda: orthanc.isAlive(), 5000, evaluateInterval = 0.1):
169
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 164
diff changeset
74 print("Orthanc failed to start")
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 164
diff changeset
75 exit(-2)
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 164
diff changeset
76 endTime = time.time()
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 164
diff changeset
77
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 164
diff changeset
78 startupTimeResult.add((endTime - startTime) * 1000)
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 164
diff changeset
79 startupTimeResult.compute()
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 164
diff changeset
80 self._results.append(startupTimeResult)
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
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
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
83
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
84 def stopOrthanc(self):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
85 if self._orthancProcess is not None:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
86 self._orthancProcess.terminate()
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
87 self._orthancProcess.wait()
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
88
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
89 def initializeDb(self):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
90 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
91 dbPopulator.populate(self.label)
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
92
160
6995d5d12d88 filtering tests
am@osimis.io
parents: 158
diff changeset
93 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
94
160
6995d5d12d88 filtering tests
am@osimis.io
parents: 158
diff changeset
95 for test in tests:
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
96 test.setOrthancClient(OrthancClient("http://127.0.0.1:8042"))
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
97 test.setRepeatCount(self._repeatCount)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
98 result = test.run()
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
99 print(str(result))
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
100
169
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 164
diff changeset
101 self._results.append(result)
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 164
diff changeset
102 return self._results
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
103
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
104 def clearDb(self):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
105 if self._dbServer is not None:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
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
6995d5d12d88 filtering tests
am@osimis.io
parents: 158
diff changeset
109 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
110
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
111 def generateOrthancConfigurationFile(self, pluginsPath: str):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
112
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
113 ConfigFileBuilder.generate(
160
6995d5d12d88 filtering tests
am@osimis.io
parents: 158
diff changeset
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
6995d5d12d88 filtering tests
am@osimis.io
parents: 158
diff changeset
116 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
117 dbType=self._dbType,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
118 dbSize=self._dbSize,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
119 port=self._port
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
120 )