Skip to content
Draft
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
40 changes: 40 additions & 0 deletions tests/model/test_error_summary.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import datetime
from unittest.mock import MagicMock, patch

import pytest

from treeherder.model.error_summary import (
cache_clean_error_line,
get_cleaned_line,
get_crash_signature,
get_error_search_term_and_path,
get_error_summary,
)

LINE_CLEANING_TEST_CASES = (
Expand Down Expand Up @@ -376,3 +380,39 @@ def test_get_blacklisted_search_term(line, exp_search_info):
def test_cache_error_line_cleaning(line, exp_cache_line_cleaned):
actual_cache_line_cleaned = cache_clean_error_line(line)
assert actual_cache_line_cleaned == exp_cache_line_cleaned


def _fake_job(repository_name):
"""A minimal stand-in for a Job with just what get_error_summary reads
before it returns early on an empty queryset."""
job = MagicMock()
job.id = 1
job.repository.name = repository_name
job.submit_time = datetime.datetime(2024, 1, 15, 12, 0, 0)
return job


ERROR_LINE_CACHE_KEYROOT_CASES = (
("comm-central", "cc_error_lines"),
("autoland", "mc_error_lines"),
("mozilla-central", "mc_error_lines"),
("try", "mc_error_lines"),
)


@pytest.mark.parametrize(("repository_name", "expected_keyroot"), ERROR_LINE_CACHE_KEYROOT_CASES)
@patch("treeherder.model.error_summary.MemDBCache")
@patch("treeherder.model.error_summary.cache")
def test_error_line_cache_selected_by_repository_name(
mock_cache, mock_memdbcache, repository_name, expected_keyroot
):
"""Only comm-central uses the cc_error_lines cache; everything else uses
mc_error_lines. The keyroot is chosen from the repository *name*, so a
comm-central job must not fall through to the mozilla-central namespace."""
# No cached error summary, so we proceed to the error-line cache selection.
mock_cache.get.return_value = None
# Empty queryset makes get_error_summary return early right after it picks
# the error-line cache, so no DB/log processing is needed.
get_error_summary(_fake_job(repository_name), queryset=[])

mock_memdbcache.assert_called_once_with(expected_keyroot)
6 changes: 5 additions & 1 deletion treeherder/model/error_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ def get_error_summary(job, queryset=None):
return cached_error_summary

# add support for error line caching
if job.repository == "comm-central":
# job.repository is a Repository instance, so compare its name rather than
# the instance itself (which is never equal to a string). Without .name,
# comm-central jobs fell through to the "mc_error_lines" cache and shared a
# namespace with mozilla-central/autoland error-line counts.
if job.repository.name == "comm-central":
lcache = MemDBCache("cc_error_lines")
else:
lcache = MemDBCache("mc_error_lines")
Expand Down