Skip to content

Commit

Permalink
Validate diff adds and omits from corupted cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMind committed Nov 13, 2024
1 parent 4d245ac commit 633fbd5
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/olympia/blocklist/tests/test_mlbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,27 +464,34 @@ def test_diff_block_soft_to_hard(self):
}

def test_diff_invalid_cache(self):
addon, _ = self._blocked_addon(file_kw={'is_signed': True})
addon, block = self._blocked_addon(file_kw={'is_signed': True})
soft_blocked = self._block_version(
block, self._version(addon), block_type=BlockType.SOFT_BLOCKED
)
base = MLBF.generate_from_db()
# Overwrite the cache file with an empty object
with base.storage.open(base.data._cache_path, 'w') as f:
json.dump({}, f)
# Overwrite the cache file removing the soft blocked version
with base.storage.open(base.data._cache_path, 'r+') as f:
data = json.load(f)
del data['soft_blocked']
f.seek(0)
json.dump(data, f)
f.truncate()

previous_mlbf = MLBF.load_from_storage(base.created_at)

mlbf = MLBF.generate_from_db()

# The diff should include the blocked version because the
# corrupted cache file is replaced with empty lists
# The diff should include the soft blocked version because it was removed
# and should not include the blocked version because it was not changed
assert mlbf.generate_diffs(previous_mlbf=previous_mlbf) == {
BlockType.BLOCKED: (
BlockType.BLOCKED: ([], [], 0),
BlockType.SOFT_BLOCKED: (
MLBF.hash_filter_inputs(
[(addon.block.guid, addon.current_version.version)]
[(soft_blocked.block.guid, soft_blocked.version.version)]
),
[],
1,
),
BlockType.SOFT_BLOCKED: ([], [], 0),
}

def test_generate_stash_returns_expected_stash(self):
Expand Down

0 comments on commit 633fbd5

Please sign in to comment.