Skip to content

Commit

Permalink
Synchronize the results fields after issue #5826
Browse files Browse the repository at this point in the history
The previously reported issue at

avocado-framework/avocado#5826

about inconsistency in the data fields collected for current test
results and the ones from previous json results was followed by a
pull request #5826

avocado-framework/avocado#5866

which now provides the changes needed to get rid of a local todo.
  • Loading branch information
pevogam committed Oct 17, 2024
1 parent 8844677 commit 7807e52
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
7 changes: 2 additions & 5 deletions avocado_i2n/plugins/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,11 @@ async def run_test_node(self, node: TestNode, status_timeout: int = 10) -> bool:
)
)
if len(node.results) > 0:
# TODO: avocado's choice of result attributes is not uniform for past and current results
def get_duration(x: dict[str, str]) -> float:
return float(x.get("time_elapsed", x["time"]))

duration = get_duration(test_result)
duration = float(test_result["time_elapsed"])
max_allowed = max(
[
get_duration(r)
float(r["time_elapsed"])
for r in node.results
if r["status"] == "PASS"
],
Expand Down
30 changes: 15 additions & 15 deletions selftests/isolation/test_cartesian_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1975,7 +1975,7 @@ def test_pull_locations(self):
worker.params["nets_host"] = "some_host"
# could also be result from a previous job, not determined here
parent_node.results = [{"name": "tutorial1.net1",
"status": "PASS", "time": 3}]
"status": "PASS", "time_elapsed": 3}]
# parent nodes was parsed as dependency of node via its vm1 object
node.descend_from_node(parent_node, mock.MagicMock(long_suffix="vm1"))

Expand Down Expand Up @@ -2019,7 +2019,7 @@ def test_pull_locations_bridged(self):
worker2.params["nets_host"] = "other_host"
# could also be result from a previous job, not determined here
parent_node1.results = [{"name": "tutorial1.net1",
"status": "PASS", "time": 3}]
"status": "PASS", "time_elapsed": 3}]
# parent nodes was parsed as dependency of node via its vm1 object
node1.descend_from_node(parent_node1, mock.MagicMock(long_suffix="vm1"))
node2.descend_from_node(parent_node2, mock.MagicMock(long_suffix="vm1"))
Expand Down Expand Up @@ -2996,7 +2996,7 @@ def test_traverse_motif_all(self):
async def delayed_traverse_wrapper(*args, **kwards):
test_node, worker = args[0], args[1]
test_node.finished_worker = worker
test_node.results = [{"name": "test", "status": "PASS", "time": 3}]
test_node.results = [{"name": "test", "status": "PASS", "time_elapsed": 3}]
await asyncio.sleep(0.01)
async def reverse_wrapper(*args, **kwards):
pass
Expand Down Expand Up @@ -3048,7 +3048,7 @@ def test_overwrite_params_and_restrs(self):
async def traverse_wrapper(*args, **kwards):
test_node, worker = args[0], args[1]
test_node.finished_worker = worker
test_node.results = [{"status": "PASS", "time": 3}]
test_node.results = [{"status": "PASS", "time_elapsed": 3}]
async def reverse_wrapper(*args, **kwards):
pass
graph.traverse_node.side_effect = traverse_wrapper
Expand Down Expand Up @@ -3193,9 +3193,9 @@ def test_run_warn_duration(self):
net = test_objects[-1]
test_node = TestGraph.parse_node_from_object(net, "normal..tutorial1", params=self.config["param_dict"].copy())

test_node.results = [{"status": "PASS", "time": 3}]
test_node.results = [{"status": "PASS", "time_elapsed": 3}]
DummyTestRun.asserted_tests = [
{"shortname": "^normal.nongui.quicktest.tutorial1.vm1", "vms": "^vm1$", "_status": "PASS", "_time": "10"},
{"shortname": "^normal.nongui.quicktest.tutorial1.vm1", "vms": "^vm1$", "_status": "PASS", "_time_elapsed": "10"},
]
test_node.started_worker = "some-worker-since-only-traversal-allowed"
to_run = self.runner.run_test_node(test_node)
Expand Down Expand Up @@ -3424,12 +3424,12 @@ def test_rerun_previous_job_default(self):
# results from the previous job (inclusive of setup that should now be skipped)
on_customize_tests = [n.params["name"] for n in graph.get_nodes(param_val="on_customize")]
self.assertEqual(len(on_customize_tests), 2)
self.runner.previous_results += [{"name": on_customize_tests[0], "status": "PASS", "time": 1}]
self.runner.previous_results += [{"name": on_customize_tests[1], "status": "PASS", "time": 1}]
self.runner.previous_results += [{"name": node11.params["name"], "status": "PASS", "time": 1}]
self.runner.previous_results += [{"name": node12.params["name"], "status": "FAIL", "time": 0.2}]
self.runner.previous_results += [{"name": node21.params["name"].replace("leaves", "all"), "status": "FAIL", "time": 0.2}]
self.runner.previous_results += [{"name": node22.params["name"].replace("leaves", "all"), "status": "PASS", "time": 1}]
self.runner.previous_results += [{"name": on_customize_tests[0], "status": "PASS", "time_elapsed": 1}]
self.runner.previous_results += [{"name": on_customize_tests[1], "status": "PASS", "time_elapsed": 1}]
self.runner.previous_results += [{"name": node11.params["name"], "status": "PASS", "time_elapsed": 1}]
self.runner.previous_results += [{"name": node12.params["name"], "status": "FAIL", "time_elapsed": 0.2}]
self.runner.previous_results += [{"name": node21.params["name"].replace("leaves", "all"), "status": "FAIL", "time_elapsed": 0.2}]
self.runner.previous_results += [{"name": node22.params["name"].replace("leaves", "all"), "status": "PASS", "time_elapsed": 1}]

# include flat and other types of nodes by traversing partially parsed graph
graph = TestGraph()
Expand Down Expand Up @@ -3477,9 +3477,9 @@ def test_rerun_previous_job_status(self):
)
node1, node2 = graph.get_nodes(param_val="tutorial2")
# results from the previous job (inclusive of setup that should now be skipped)
self.runner.previous_results += [{"name": graph.get_nodes(param_val="on_customize", unique=True).params["name"], "status": "PASS", "time": 1}]
self.runner.previous_results += [{"name": node1.params["name"], "status": "PASS", "time": 1}]
self.runner.previous_results += [{"name": node2.params["name"], "status": "FAIL", "time": 0.2}]
self.runner.previous_results += [{"name": graph.get_nodes(param_val="on_customize", unique=True).params["name"], "status": "PASS", "time_elapsed": 1}]
self.runner.previous_results += [{"name": node1.params["name"], "status": "PASS", "time_elapsed": 1}]
self.runner.previous_results += [{"name": node2.params["name"], "status": "FAIL", "time_elapsed": 0.2}]

# include flat and other types of nodes by traversing partially parsed graph
graph = TestGraph()
Expand Down
8 changes: 4 additions & 4 deletions selftests/isolation/unittest_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ def get_test_result(self):
name = self.current_test_dict["name"]
# allow tests to specify the status they expect
status = self.expected_test_dict.get("_status", "PASS")
time = self.expected_test_dict.get("_time", "1")
self.add_test_result(uid, name, status, time)
time_elapsed = self.expected_test_dict.get("_time_elapsed", "1")
self.add_test_result(uid, name, status, time_elapsed)
if status in ["ERROR", "FAIL"] and self.current_test_dict.get("abort_on_error", "no") == "yes":
raise exceptions.TestSkipError("God wanted this test to abort")
return status not in ["ERROR", "FAIL"]

def add_test_result(self, uid, name, status, time, logdir="."):
def add_test_result(self, uid, name, status, time_elapsed, logdir="."):
mocktestid = type("Mock", (), {"uid": uid, "name": name})()
# or else have to set name attribute separately since "name" is reserved by MagicMock
# mocktestid = mock.MagicMock(uid=uid, name=name)
# mocktestid.name = name
self.test_results.append({
"name": mocktestid,
"status": status,
"time": time,
"time_elapsed": time_elapsed,
"logdir": logdir,
})

Expand Down

0 comments on commit 7807e52

Please sign in to comment.