|
17 | 17 | from typing import List
|
18 | 18 | from pydantic import parse
|
19 | 19 | from pydantic_yaml import YamlModel, main
|
| 20 | +import time |
20 | 21 |
|
21 | 22 | class FindingConfig(YamlModel):
|
22 | 23 | source: str
|
@@ -57,6 +58,8 @@ def parse_arguments():
|
57 | 58 | parser.add_argument("--debug", action="store_true")
|
58 | 59 | parser.add_argument("--configs","-c",help="Location of the test configurations directory", default=os.path.dirname(os.path.realpath(__file__)) + "/test_configs/")
|
59 | 60 | parser.add_argument("--url","-u",help="Base URL for API testing",default="http://localhost:8080/")
|
| 61 | + parser.add_argument("--max-time", "-t", help="Time in ms to use as a max time a single response is allowed to take", type=int, default=1000) |
| 62 | + |
60 | 63 | config = parser.parse_args()
|
61 | 64 | return config
|
62 | 65 |
|
@@ -104,8 +107,14 @@ def run_all_tests(self):
|
104 | 107 |
|
105 | 108 | def run_one_test(self, test_config):
|
106 | 109 | self.logger.debug(f'Starting test {test_config.name}')
|
| 110 | + start_time = time.monotonic() |
107 | 111 | API_result = self.send_test_to_API(test_config)
|
| 112 | + time_taken = time.monotonic() - start_time |
108 | 113 | success = self.check_test_result(test_config, API_result)
|
| 114 | + if time_taken > self.config.max_time/1000: |
| 115 | + success = False |
| 116 | + self.failed_test_count += 1 |
| 117 | + self.failures.append((test_config,f'Test {test_config.name} took {int(time_taken*1000)}ms. Exceeded max of {self.config.max_time}ms.')) |
109 | 118 | return success
|
110 | 119 |
|
111 | 120 | def send_test_to_API(self, test_config):
|
|
0 commit comments