Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit eafe3da

Browse files
author
Jeremy Banker
committed
Add test run timer to ensure API response time remains acceptable
Signed-off-by: Jeremy Banker <[email protected]>
1 parent 77895db commit eafe3da

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tests/automated_functional_test/functional_test.py

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from typing import List
1818
from pydantic import parse
1919
from pydantic_yaml import YamlModel, main
20+
import time
2021

2122
class FindingConfig(YamlModel):
2223
source: str
@@ -57,6 +58,8 @@ def parse_arguments():
5758
parser.add_argument("--debug", action="store_true")
5859
parser.add_argument("--configs","-c",help="Location of the test configurations directory", default=os.path.dirname(os.path.realpath(__file__)) + "/test_configs/")
5960
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+
6063
config = parser.parse_args()
6164
return config
6265

@@ -104,8 +107,14 @@ def run_all_tests(self):
104107

105108
def run_one_test(self, test_config):
106109
self.logger.debug(f'Starting test {test_config.name}')
110+
start_time = time.monotonic()
107111
API_result = self.send_test_to_API(test_config)
112+
time_taken = time.monotonic() - start_time
108113
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.'))
109118
return success
110119

111120
def send_test_to_API(self, test_config):

0 commit comments

Comments
 (0)