From 99e051875dd2c8ded5fd4be0fe13e60a6b7bbb46 Mon Sep 17 00:00:00 2001 From: Alexey Kartashov Date: Thu, 14 Nov 2024 16:46:48 +0100 Subject: [PATCH] fix(stats.py): Add a fallback for old assignments and stats This commit fixes an issue where old schedules would not be counted for tests that have not been run (but have been scheduled). This restores both the assignee icon and NOT RUN status. --- argus/backend/service/argus_service.py | 3 ++- argus/backend/service/stats.py | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/argus/backend/service/argus_service.py b/argus/backend/service/argus_service.py index b17c8110..9c860d98 100644 --- a/argus/backend/service/argus_service.py +++ b/argus/backend/service/argus_service.py @@ -622,7 +622,8 @@ def get_tests_assignees(self, group_id: UUID | str, version: str = None, plan_id release = ArgusRelease.get(id=group.release_id) if not release.perpetual: - return PlanningService().get_assignments_for_tests(group_id, version, plan_id) + if assignments := PlanningService().get_assignments_for_tests(group_id, version, plan_id): + return assignments tests = ArgusTest.filter(group_id=group_id).all() diff --git a/argus/backend/service/stats.py b/argus/backend/service/stats.py index da219efa..e1549388 100644 --- a/argus/backend/service/stats.py +++ b/argus/backend/service/stats.py @@ -11,7 +11,7 @@ from argus.backend.plugins.loader import all_plugin_models from argus.backend.util.common import chunk, get_build_number from argus.common.enums import TestStatus, TestInvestigationStatus -from argus.backend.models.web import ArgusGithubIssue, ArgusRelease, ArgusGroup, ArgusTest,\ +from argus.backend.models.web import ArgusGithubIssue, ArgusRelease, ArgusGroup, ArgusScheduleTest, ArgusTest,\ ArgusTestRunComment, ArgusUserView from argus.backend.db import ScyllaCluster @@ -248,6 +248,7 @@ def __init__(self, release: ArgusRelease) -> None: self.issues: list[ArgusGithubIssue] = [] self.comments: list[ArgusTestRunComment] = [] self.plans: list[ArgusReleasePlan] = [] + self.schedules = {} self.forced_collection = False self.rows = [] self.all_tests = [] @@ -285,6 +286,11 @@ def collect(self, rows: list[TestRunStatRow], limited=False, force=False, dict: if not self.release.perpetual and not limited: plans: list[ArgusReleasePlan] = list(ArgusReleasePlan.filter(release_id=self.release.id).all()) self.plans = plans if not filter else [plan for plan in plans if version_filter == plan.target_version] + self.test_schedules = reduce( + lambda acc, row: acc[row["test_id"]].append(row) or acc, + ArgusScheduleTest.filter(release_id=self.release.id).all(), + defaultdict(list) + ) self.rows = rows self.dict = dict @@ -361,7 +367,8 @@ def collect(self, limited=False): stats = TestStats( test=test, parent_group=self, - scheduled=is_scheduled + scheduled=is_scheduled, + schedules=self.parent_release.test_schedules.get(test.id, []), ) stats.collect(limited=limited) self.tests.append(stats) @@ -378,7 +385,8 @@ def __init__( self, test: ArgusTest, parent_group: GroupStats, - scheduled: bool = False + scheduled: bool = False, + schedules: list[ArgusScheduleTest] | None = None, ) -> None: self.test = test self.parent_group = parent_group @@ -389,6 +397,8 @@ def __init__( self.has_bug_report = False self.has_comments = False self.is_scheduled = scheduled + self.schedules = schedules if schedules else tuple() + self.is_scheduled_legacy = len(self.schedules) > 0 # TODO: Remove once old scheduling system is removed self.tracked_run_number = None def to_dict(self) -> dict: @@ -417,7 +427,7 @@ def collect(self, limited=False): try: last_run = last_runs[0] except IndexError: - self.status = TestStatus.NOT_RUN if self.is_scheduled else TestStatus.NOT_PLANNED + self.status = TestStatus.NOT_RUN if self.is_scheduled or self.is_scheduled_legacy else TestStatus.NOT_PLANNED self.parent_group.increment_status(status=self.status) return status_map = generate_field_status_map(last_runs)