Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix a bug which could lead to incorrect state #13278

Merged
merged 11 commits into from
Jul 15, 2022
Prev Previous commit
Next Next commit
Better test for delta IDs
  • Loading branch information
erikjohnston committed Jul 15, 2022
commit 30d720076b3278ab3b8ec275f13a9e717f1d6d8a
14 changes: 12 additions & 2 deletions tests/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,25 +768,35 @@ def test_make_state_cache_entry(self):
("a", ""): "E",
("b", ""): "E",
("c", ""): "E",
("d", ""): "E",
}

# old_state_1 has fewer differences to new_state than old_state_2, but
# the delta involves deleting a key, which isn't allowed in the deltas,
# so we should pick old_state_2 as the prev_group.

# `old_state_1` has two differences: `a` and `e`
old_state_1 = {
("a", ""): "F",
("b", ""): "E",
("c", ""): "E",
("d", ""): "E",
("e", ""): "E",
}

# `old_state_2` has three differences: `a`, `c` and `d`
old_state_2 = {
("a", ""): "F",
("b", ""): "F",
("b", ""): "E",
("c", ""): "F",
("d", ""): "F",
}

entry = _make_state_cache_entry(new_state, {1: old_state_1, 2: old_state_2})

self.assertEqual(entry.prev_group, 2)
self.assertEqual(entry.delta_ids, new_state)

# There are two changes from `old_state_2` to `new_state`
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
self.assertEqual(
entry.delta_ids, {("a", ""): "E", ("c", ""): "E", ("d", ""): "E"}
)