Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continue to trim TestCase #400

Merged
merged 3 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions grizzly/common/iomanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 14 additions & 13 deletions grizzly/common/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class TestCase:
"hang",
"https",
"input_fname",
"time_limit",
"timestamp",
"version",
"_files",
Expand All @@ -60,7 +59,6 @@ def __init__(
adapter_name,
data_path=None,
input_fname=None,
time_limit=None,
timestamp=None,
):
assert entry_point
Expand All @@ -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={})
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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", {})
Expand Down
6 changes: 2 additions & 4 deletions grizzly/common/test_iomanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -58,18 +58,16 @@ 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
assert not iom.tests
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
Expand Down
3 changes: 1 addition & 2 deletions grizzly/common/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions grizzly/common/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions grizzly/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion grizzly/reduce/test_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions grizzly/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Loading