diff --git a/grizzly/common/iomanager.py b/grizzly/common/iomanager.py index af434cd5..34004d87 100644 --- a/grizzly/common/iomanager.py +++ b/grizzly/common/iomanager.py @@ -46,9 +46,9 @@ def commit(self): if len(self.tests) > self._report_size: self.tests.pop(0).cleanup() - def create_testcase(self, adapter_name, time_limit): + def create_testcase(self, adapter_name): assert self._test is None - self._test = TestCase(self.page_name(), adapter_name, time_limit=time_limit) + self._test = TestCase(self.page_name(), adapter_name) # reset redirect map self.server_map.set_redirect( "grz_current_test", self.page_name(), required=False diff --git a/grizzly/common/storage.py b/grizzly/common/storage.py index afd1e161..e4c0d2d4 100644 --- a/grizzly/common/storage.py +++ b/grizzly/common/storage.py @@ -46,7 +46,6 @@ class TestCase: "hang", "https", "input_fname", - "time_limit", "timestamp", "version", "_files", @@ -60,7 +59,6 @@ def __init__( adapter_name, data_path=None, input_fname=None, - time_limit=None, timestamp=None, ): assert entry_point @@ -73,7 +71,6 @@ def __init__( self.https = False self.input_fname = input_fname # file that was used to create the test case self.entry_point = self.sanitize_path(entry_point) - self.time_limit = time_limit self.timestamp = time() if timestamp is None else timestamp self.version = __version__ self._files = TestFileMap(optional={}, required={}) @@ -237,7 +234,6 @@ def clone(self): self.entry_point, self.adapter_name, input_fname=self.input_fname, - time_limit=self.time_limit, timestamp=self.timestamp, ) result.assets = dict(self.assets) @@ -307,17 +303,23 @@ def dump(self, dst_path, include_details=False): if include_details: assert isinstance(self.env_vars, dict) info = { - "adapter": self.adapter_name, - "duration": self.duration, - "env": self.env_vars, - "hang": self.hang, "https": self.https, - "input": Path(self.input_fname).name if self.input_fname else None, "target": self.entry_point, - "time_limit": self.time_limit, - "timestamp": self.timestamp, - "version": self.version, } + if self.adapter_name: + info["adapter"] = self.adapter_name + if self.duration: + info["duration"] = self.duration + if self.env_vars: + info["env"] = self.env_vars + if self.hang: + info["hang"] = self.hang + if self.input_fname: + info["input"] = Path(self.input_fname).name + if self.timestamp: + info["timestamp"] = self.timestamp + if self.version: + info["version"] = self.version # save target assets and update meta data if self.assets: assert isinstance(self.assets, dict) @@ -389,7 +391,6 @@ def load(cls, path, entry_point=None, catalog=False): info.get("adapter", None), data_path=entry_point.parent, input_fname=info.get("input", None), - time_limit=info.get("time_limit", None), timestamp=info.get("timestamp", 0), ) test.assets = info.get("assets", {}) diff --git a/grizzly/common/test_iomanager.py b/grizzly/common/test_iomanager.py index ce6479e8..2ce2e163 100644 --- a/grizzly/common/test_iomanager.py +++ b/grizzly/common/test_iomanager.py @@ -31,7 +31,7 @@ def test_iomanager_02(report_size, iters): with IOManager(report_size=report_size) as iom: assert not iom.tests for current in range(1, iters + 1): - tcase = iom.create_testcase("test-adapter", 10) + tcase = iom.create_testcase("test-adapter") assert iom._generated == current assert iom._test is not None precommit_size = len(iom.tests) @@ -58,7 +58,6 @@ def test_iomanager_03(): def test_iomanager_04(): """test IOManager.create_testcase()""" - time_limit = 10 with IOManager() as iom: assert iom._generated == 0 assert iom._report_size == 1 @@ -66,10 +65,9 @@ def test_iomanager_04(): assert not iom.server_map.dynamic assert not iom.server_map.include assert not iom.server_map.redirect - tcase = iom.create_testcase("test-adapter", time_limit) + tcase = iom.create_testcase("test-adapter") assert tcase is not None assert not any(tcase.optional) - assert tcase.time_limit == time_limit assert "grz_current_test" in iom.server_map.redirect assert iom.server_map.redirect["grz_current_test"].target == tcase.entry_point assert "grz_next_test" in iom.server_map.redirect diff --git a/grizzly/common/test_storage.py b/grizzly/common/test_storage.py index 1bff54b8..6416327d 100644 --- a/grizzly/common/test_storage.py +++ b/grizzly/common/test_storage.py @@ -368,7 +368,6 @@ def test_testcase_15(tmp_path): org.https = not org.https org.hang = not org.hang org.input_fname = "infile" - org.time_limit = 456 org.add_from_bytes(b"a", org.entry_point) org.assets = {"sample": asset.name} org.assets_path = asset_path @@ -406,7 +405,7 @@ def test_testcase_16(): ) def test_testcase_17(tmp_path, remote_assets): """test TestCase.clone()""" - with TestCase("test.htm", "adpt", input_fname="fn", time_limit=2) as src: + with TestCase("test.htm", "adpt", input_fname="fn") as src: if remote_assets: src.assets = {"foo": "asset.file"} src.assets_path = tmp_path diff --git a/grizzly/common/test_utils.py b/grizzly/common/test_utils.py index 112542e7..8b8011cd 100644 --- a/grizzly/common/test_utils.py +++ b/grizzly/common/test_utils.py @@ -66,9 +66,9 @@ def test_configure_logging_01(mocker, env, log_level): # use defaults instead of low test values (None, None, [1], (DEFAULT_TIME_LIMIT, DEFAULT_TIME_LIMIT + TIMEOUT_DELAY)), # use duration from test case - (None, None, [99.1], (100, 100 + TIMEOUT_DELAY)), + (None, None, [90.1], (100, 100 + TIMEOUT_DELAY)), # multiple tests - (None, None, [99.9, 10, 25], (100, 100 + TIMEOUT_DELAY)), + (None, None, [90.9, 10, 25], (100, 100 + TIMEOUT_DELAY)), # specify time limit (100, None, [0], (100, 100 + TIMEOUT_DELAY)), # specify timeout (> DEFAULT_TIME_LIMIT) diff --git a/grizzly/common/utils.py b/grizzly/common/utils.py index 042a9a60..dd4f1049 100644 --- a/grizzly/common/utils.py +++ b/grizzly/common/utils.py @@ -6,7 +6,6 @@ from importlib.metadata import PackageNotFoundError, version from ipaddress import IPv4Address from logging import DEBUG, basicConfig, getLogger -from math import ceil from os import getenv, getpid from pathlib import Path from shutil import rmtree @@ -243,8 +242,8 @@ def time_limits( time_limit (int): Test time limit. timeout (int): Iteration timeout. tests (iterable): Testcases that may contain time limit values. - default_limit (int): Value to used as default time limit. - timeout_delay (int): Value to used as delay when calculating timeout. + default_limit (int): Value to use as default time limit. + timeout_delay (int): Value to use as delay when calculating timeout. Returns: tuple (int, int): Time limit and timeout. @@ -257,7 +256,8 @@ def time_limits( # use default_limit as a minimum test_limits = [default_limit] if tests: - test_limits.extend(int(ceil(x.duration)) for x in tests if x.duration) + # add small time buffer to duration + test_limits.extend(int(x.duration) + 10 for x in tests if x.duration) time_limit = max(test_limits) assert time_limit > 0 # calculate timeout diff --git a/grizzly/reduce/test_strategies.py b/grizzly/reduce/test_strategies.py index 8cd7514c..c6ba5d00 100644 --- a/grizzly/reduce/test_strategies.py +++ b/grizzly/reduce/test_strategies.py @@ -40,7 +40,7 @@ def update(self, success): pass # create testcase - with TestCase("a.htm", "adpt", input_fname="fn", time_limit=2) as test: + with TestCase("a.htm", "adpt", input_fname="fn") as test: test.duration = 1.2 test.hang = is_hang test.add_from_bytes(b"123", test.entry_point) diff --git a/grizzly/session.py b/grizzly/session.py index 1e126548..1465321e 100644 --- a/grizzly/session.py +++ b/grizzly/session.py @@ -129,9 +129,9 @@ def display_status(self, log_limiter): elif log_limiter.ready(self.status.iteration, self.target.monitor.launches): LOG.info("I%04d-R%02d ", self.status.iteration, self.status.results.total) - def generate_testcase(self, time_limit): + def generate_testcase(self): LOG.debug("calling iomanager.create_testcase()") - test = self.iomanager.create_testcase(self.adapter.name, time_limit) + test = self.iomanager.create_testcase(self.adapter.name) LOG.debug("calling adapter.generate()") with self.status.measure("generate"): self.adapter.generate(test, self.iomanager.server_map) @@ -204,7 +204,7 @@ def run( # TODO: avoid running test case if runner.startup_failure is True # create and populate a test case - current_test = self.generate_testcase(time_limit) + current_test = self.generate_testcase() # display status self.display_status(log_limiter=log_limiter) # run test case