Mercurial > hg > orthanc-tests
comparison PerfsDb/TestConfig.py @ 169:85a2074f8794
measuring orthanc startup time
author | am@osimis.io |
---|---|
date | Fri, 31 Aug 2018 11:01:40 +0200 |
parents | ff939d07989f |
children | a38c3cbc74dd |
comparison
equal
deleted
inserted
replaced
168:11b7e1fa7aff | 169:85a2074f8794 |
---|---|
1 import typing | 1 import typing |
2 import subprocess | 2 import subprocess |
3 import os | 3 import os |
4 import shutil | 4 import shutil |
5 import time | |
6 from osimis_timer import TimeOut | |
5 from orthancRestApi import OrthancClient | 7 from orthancRestApi import OrthancClient |
6 | 8 |
7 from DbSize import DbSize | 9 from DbSize import DbSize |
8 from DbType import DbType | 10 from DbType import DbType |
9 from ConfigFileBuilder import ConfigFileBuilder | 11 from ConfigFileBuilder import ConfigFileBuilder |
25 self._dbServer = dbServer | 27 self._dbServer = dbServer |
26 self.label = label | 28 self.label = label |
27 self._port = None | 29 self._port = None |
28 self._orthancProcess = None | 30 self._orthancProcess = None |
29 self._repeatCount = 20 | 31 self._repeatCount = 20 |
32 self._results = [] | |
30 | 33 |
31 if dbServer is not None: | 34 if dbServer is not None: |
32 self._dbType = dbServer.dbType | 35 self._dbType = dbServer.dbType |
33 self._dbServer.setLabel(self.label) | 36 self._dbServer.setLabel(self.label) |
34 self._port = dbServer.port | 37 self._port = dbServer.port |
58 if traceEnabled: | 61 if traceEnabled: |
59 runOrthancCommand.append("--trace") | 62 runOrthancCommand.append("--trace") |
60 elif verboseEnabled: | 63 elif verboseEnabled: |
61 runOrthancCommand.append("--verbose") | 64 runOrthancCommand.append("--verbose") |
62 | 65 |
66 startupTimeResult = TestResult("Startup time") | |
67 startTime = time.time() | |
68 | |
63 self._orthancProcess = subprocess.Popen(runOrthancCommand) | 69 self._orthancProcess = subprocess.Popen(runOrthancCommand) |
64 | 70 |
65 print("Waiting for Orthanc to start") | 71 print("Waiting for Orthanc to start") |
66 orthanc.waitStarted(timeout=30) | 72 if not TimeOut.waitUntilCondition(lambda: orthanc.isAlive(), 3000, evaluateInterval = 0.1): |
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) | |
67 print("Orthanc has started") | 80 print("Orthanc has started") |
68 return True | 81 return True |
69 | 82 |
70 def stopOrthanc(self): | 83 def stopOrthanc(self): |
71 if self._orthancProcess is not None: | 84 if self._orthancProcess is not None: |
76 dbPopulator = DbPopulator(orthanc=OrthancClient("http://127.0.0.1:8042"), dbSize=self._dbSize) | 89 dbPopulator = DbPopulator(orthanc=OrthancClient("http://127.0.0.1:8042"), dbSize=self._dbSize) |
77 dbPopulator.populate(self.label) | 90 dbPopulator.populate(self.label) |
78 | 91 |
79 def runTests(self, tests: typing.List[Test]) -> typing.List[TestResult]: | 92 def runTests(self, tests: typing.List[Test]) -> typing.List[TestResult]: |
80 | 93 |
81 results = [] | |
82 for test in tests: | 94 for test in tests: |
83 test.setOrthancClient(OrthancClient("http://127.0.0.1:8042")) | 95 test.setOrthancClient(OrthancClient("http://127.0.0.1:8042")) |
84 test.setRepeatCount(self._repeatCount) | 96 test.setRepeatCount(self._repeatCount) |
85 result = test.run() | 97 result = test.run() |
86 print(str(result)) | 98 print(str(result)) |
87 | 99 |
88 results.append(result) | 100 self._results.append(result) |
89 return results | 101 return self._results |
90 | 102 |
91 def clearDb(self): | 103 def clearDb(self): |
92 if self._dbServer is not None: | 104 if self._dbServer is not None: |
93 self._dbServer.clear() | 105 self._dbServer.clear() |
94 | 106 |