Skip to content

Commit

Permalink
Replace TestCase.landing_page with TestCase.entry_point
Browse files Browse the repository at this point in the history
  • Loading branch information
tysmith committed Oct 27, 2023
1 parent 65c55a2 commit 13019e4
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 61 deletions.
9 changes: 4 additions & 5 deletions grizzly/adapter/no_op_adapter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,15 @@ def setup(self, _input, _server_map):
)

def generate(self, testcase, _server_map):
"""Since the test case has already been created just add the data to the
TestCase.
"""The test case contents have been created now add the data to the TestCase.
Also all TestCases require an entry point and the one expected by Grizzly
is provided in `testcase.landing_page` so use it as the file name for
All TestCases require an entry point and the one expected by Grizzly
is provided in `testcase.entry_point` so use it as the file name for
the test.
Args:
testcase (grizzly.common.storage.TestCase): TestCase to be populated.
_server_map (sapphire.server_map.ServerMap): Unused.
_server_map (sapphire.server_map.ServerMap): Unused in this example.
Returns:
None
Expand Down
1 change: 0 additions & 1 deletion grizzly/common/iomanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def commit(self):

def create_testcase(self, adapter_name, time_limit):
assert self._test is None
# create testcase object and landing page names
self._test = TestCase(self.page_name(), adapter_name, time_limit=time_limit)
# reset redirect map
self.server_map.set_redirect(
Expand Down
10 changes: 5 additions & 5 deletions grizzly/common/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ def post_launch(self, delay=-1):
with TestCase("post_launch_delay.html", "None") as content:
content.add_from_file(
Path(__file__).parent / "post_launch_delay.html",
content.landing_page,
content.entry_point,
copy=True,
)
srv_map = ServerMap()
srv_map.set_redirect("grz_start", content.landing_page, required=False)
srv_map.set_redirect("grz_start", content.entry_point, required=False)
srv_map.set_redirect("grz_continue", "grz_start", required=True)
# temporarily disable server timeout
srv_timeout = self._server.timeout
Expand Down Expand Up @@ -290,7 +290,7 @@ def run(
result = RunResult(
served,
duration,
attempted=testcase.landing_page in served,
attempted=testcase.entry_point in served,
timeout=server_status == Served.TIMEOUT,
)
# TODO: fix calling TestCase.add_batch() for multi-test replay
Expand Down Expand Up @@ -344,7 +344,7 @@ def run(
else:
# something is wrong so close the target
# previous iteration put target in a bad state?
LOG.debug("landing page %r not served!", testcase.landing_page)
LOG.debug("entry point not served (%r)", testcase.entry_point)
self._target.close()
# detect startup failures
if self.initial:
Expand Down Expand Up @@ -374,7 +374,7 @@ class RunResult:
"""A RunResult holds result details from a call to Runner.run().
Attributes:
attempted (bool): Test landing page (entry point) was requested.
attempted (bool): Test entry point was requested.
duration (float): Time spent waiting for test contents to be served.
served (tuple(str)): Files that were served.
status (int): Result status of test.
Expand Down
40 changes: 30 additions & 10 deletions grizzly/common/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
from collections import namedtuple
from itertools import chain, product
from logging import getLogger
from os.path import normpath, split
from pathlib import Path
from shutil import copyfile, move, rmtree
Expand All @@ -21,6 +22,9 @@
__credits__ = ["Tyson Smith"]


LOG = getLogger(__name__)


class TestCaseLoadFailure(Exception):
"""Raised when loading a TestCase fails"""

Expand All @@ -39,11 +43,11 @@ class TestCase:
"adapter_name",
"assets",
"duration",
"entry_point",
"env_vars",
"hang",
"https",
"input_fname",
"landing_page",
"time_limit",
"timestamp",
"version",
Expand All @@ -53,21 +57,21 @@ class TestCase:

def __init__(
self,
landing_page,
entry_point,
adapter_name,
input_fname=None,
time_limit=None,
timestamp=None,
):
assert landing_page
assert entry_point
self.adapter_name = adapter_name
self.assets = None
self.duration = None
self.env_vars = {}
self.hang = False
self.https = False
self.input_fname = input_fname # file that was used to create the test case
self.landing_page = self.sanitize_path(landing_page)
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__
Expand Down Expand Up @@ -162,8 +166,8 @@ def add_from_file(self, src_file, file_name=None, required=False, copy=False):
else:
move(src_file, test_file.data_file)

# landing_page is always 'required'
if required or test_file.file_name == self.landing_page:
# entry_point is always 'required'
if required or test_file.file_name == self.entry_point:
self._files.required.append(test_file)
else:
self._files.optional.append(test_file)
Expand All @@ -189,7 +193,7 @@ def clone(self):
TestCase: A copy of the TestCase instance.
"""
result = type(self)(
self.landing_page,
self.entry_point,
self.adapter_name,
self.input_fname,
self.time_limit,
Expand Down Expand Up @@ -278,7 +282,7 @@ def dump(self, dst_path, include_details=False):
"hang": self.hang,
"https": self.https,
"input": Path(self.input_fname).name if self.input_fname else None,
"target": self.landing_page,
"target": self.entry_point,
"time_limit": self.time_limit,
"timestamp": self.timestamp,
"version": self.version,
Expand Down Expand Up @@ -306,6 +310,22 @@ def get_file(self, path):
return tfile
return None

@property
def landing_page(self):
"""TestCase.landing_page is deprecated!
Should be replaced with TestCase.entry_page.
Args:
None
Returns:
str: TestCase.entry_page.
"""
LOG.warning(
"'TestCase.landing_page' deprecated, use 'TestCase.entry_point' in adapter"
)
return self.entry_point

@classmethod
def load(cls, path, adjacent=False):
"""Load TestCases from disk.
Expand Down Expand Up @@ -419,7 +439,7 @@ def load_single(cls, path, adjacent=False, load_assets=True, copy=True):
test.https = info.get("https", False)
test.version = info.get("version", None)
test.add_from_file(
entry_point, file_name=test.landing_page, required=True, copy=copy
entry_point, file_name=test.entry_point, required=True, copy=copy
)
if info:
# load assets
Expand Down Expand Up @@ -453,7 +473,7 @@ def load_single(cls, path, adjacent=False, load_assets=True, copy=True):
if asset_path and location.startswith(asset_path):
continue
# ignore files that have been previously loaded
if location in (test.landing_page, "test_info.json"):
if location in (test.entry_point, "test_info.json"):
continue
# NOTE: when loading all files except the entry point are
# marked as `required=False`
Expand Down
2 changes: 1 addition & 1 deletion grizzly/common/test_iomanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_iomanager_04():
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.landing_page
assert iom.server_map.redirect["grz_current_test"].target == tcase.entry_point
assert "grz_next_test" in iom.server_map.redirect
assert iom._test is not None
iom.purge()
Expand Down
14 changes: 7 additions & 7 deletions grizzly/common/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_runner_02(mocker):
target.check_result.return_value = Result.NONE
serv_files = ["a.bin"]
server.serve_path.return_value = (Served.ALL, serv_files)
testcase = mocker.Mock(spec_set=TestCase, landing_page=serv_files[0], optional=[])
testcase = mocker.Mock(spec_set=TestCase, entry_point=serv_files[0], optional=[])
# single run/iteration relaunch (not idle exit)
target.is_idle.return_value = False
runner = Runner(server, target, relaunch=1)
Expand Down Expand Up @@ -129,7 +129,7 @@ def test_runner_02(mocker):
[
# no files served
(Served.NONE, []),
# landing page not served
# entry point not served
(Served.REQUEST, ["harness"]),
],
)
Expand All @@ -139,7 +139,7 @@ def test_runner_03(mocker, srv_result, served):
server.serve_path.return_value = (srv_result, served)
target = mocker.Mock(spec_set=Target)
target.check_result.return_value = Result.NONE
testcase = mocker.Mock(spec_set=TestCase, landing_page="x", optional=[])
testcase = mocker.Mock(spec_set=TestCase, entry_point="x", optional=[])
runner = Runner(server, target)
result = runner.run([], ServerMap(), testcase)
assert runner.initial
Expand All @@ -166,7 +166,7 @@ def test_runner_04(mocker, ignore, status, idle, check_result):
"""test reporting timeout"""
server = mocker.Mock(spec_set=Sapphire)
target = mocker.Mock(spec_set=Target)
testcase = mocker.Mock(spec_set=TestCase, landing_page="a.bin", optional=[])
testcase = mocker.Mock(spec_set=TestCase, entry_point="a.bin", optional=[])
serv_files = ["a.bin", "/another/file.bin"]
server.serve_path.return_value = (Served.TIMEOUT, serv_files)
target.check_result.return_value = Result.FOUND
Expand All @@ -191,7 +191,7 @@ def test_runner_04(mocker, ignore, status, idle, check_result):
(["a.bin"], True, Result.FOUND, Result.FOUND),
# IGNORED
(["a.bin"], True, Result.IGNORED, Result.IGNORED),
# failure before serving landing page
# failure before serving entry point
(["harness"], False, Result.FOUND, Result.FOUND),
],
)
Expand All @@ -202,7 +202,7 @@ def test_runner_05(mocker, served, attempted, target_result, status):
target = mocker.Mock(spec_set=Target, launch_timeout=10)
target.check_result.return_value = target_result
target.monitor.is_healthy.return_value = False
testcase = mocker.Mock(spec_set=TestCase, landing_page="a.bin", optional=[])
testcase = mocker.Mock(spec_set=TestCase, entry_point="a.bin", optional=[])
runner = Runner(server, target)
runner.launch("http://a/")
result = runner.run([], ServerMap(), testcase)
Expand All @@ -225,7 +225,7 @@ def test_runner_06(mocker):
result = runner.run(
[],
ServerMap(),
mocker.Mock(spec_set=TestCase, landing_page=serv_files[0], optional=[]),
mocker.Mock(spec_set=TestCase, entry_point=serv_files[0], optional=[]),
)
assert result.status == Result.NONE
assert result.attempted
Expand Down
12 changes: 6 additions & 6 deletions grizzly/common/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

def test_testcase_01(tmp_path):
"""test empty TestCase"""
l_page = "land.html"
entry_point = "test.html"
adpt_name = "test-adapter"
with TestCase(l_page, adpt_name) as tcase:
assert tcase.landing_page == l_page
with TestCase(entry_point, adpt_name) as tcase:
assert tcase.entry_point == entry_point
assert tcase.assets is None
assert tcase.adapter_name == adpt_name
assert tcase.duration is None
Expand Down Expand Up @@ -223,7 +223,7 @@ def test_testcase_08(mocker, tmp_path):
assert asset
with asset:
assert "example" in asset.assets
assert dst.landing_page == "target.bin"
assert dst.entry_point == "target.bin"
assert "target.bin" in (x.file_name for x in dst._files.required)
assert "optional.bin" in (x.file_name for x in dst._files.optional)
assert "x.bin" in (x.file_name for x in dst._files.optional)
Expand Down Expand Up @@ -251,13 +251,13 @@ def test_testcase_09(tmp_path):
with TestCase.load_single(entry_point, adjacent=False) as tcase:
assert tcase.assets is None
assert not tcase.env_vars
assert tcase.landing_page == "target.bin"
assert tcase.entry_point == "target.bin"
assert "target.bin" in (x.file_name for x in tcase._files.required)
assert "optional.bin" not in (x.file_name for x in tcase._files.optional)
assert tcase.timestamp == 0
# load full test case
with TestCase.load_single(entry_point, adjacent=True) as tcase:
assert tcase.landing_page == "target.bin"
assert tcase.entry_point == "target.bin"
assert "target.bin" in (x.file_name for x in tcase._files.required)
assert "optional.bin" in (x.file_name for x in tcase._files.optional)

Expand Down
4 changes: 2 additions & 2 deletions grizzly/reduce/strategies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ def purge_unserved(self, testcases, served):
remove_testcases = []
for idx, (testcase, tc_served) in enumerate(zip(testcases, served)):
LOG.debug("testcase %d served %r", idx, tc_served)
if testcase.landing_page not in tc_served:
LOG.debug("landing page %r not served", testcase.landing_page)
if testcase.entry_point not in tc_served:
LOG.debug("entry point not served (%r)", testcase.entry_point)
remove_testcases.append(idx)
anything_purged = True
else:
Expand Down
4 changes: 2 additions & 2 deletions grizzly/replay/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,12 @@ def run(
next_idx = (test_idx + 1) % test_count
server_map.set_redirect(
"grz_next_test",
testcases[next_idx].landing_page,
testcases[next_idx].entry_point,
required=True,
)
server_map.set_redirect(
"grz_current_test",
testcases[test_idx].landing_page,
testcases[test_idx].entry_point,
required=False,
)
# run testcase
Expand Down
Loading

0 comments on commit 13019e4

Please sign in to comment.