This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better return type for
get_all_entities_changed
(#14604)
Help callers from using the return value incorrectly by ensuring that callers explicitly check if there was a cache hit or not.
- Loading branch information
1 parent
6a8310f
commit cee9445
Showing
8 changed files
with
138 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix a long-standing bug where a device list update might not be sent to clients in certain circumstances. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,19 +73,21 @@ def test_entity_has_changed_pops_off_start(self) -> None: | |
# The oldest item has been popped off | ||
self.assertTrue("[email protected]" not in cache._entity_to_key) | ||
|
||
self.assertEqual(cache.get_all_entities_changed(3), ["[email protected]"]) | ||
self.assertIsNone(cache.get_all_entities_changed(2)) | ||
self.assertEqual( | ||
cache.get_all_entities_changed(3).entities, ["[email protected]"] | ||
) | ||
self.assertFalse(cache.get_all_entities_changed(2).hit) | ||
|
||
# If we update an existing entity, it keeps the two existing entities | ||
cache.entity_has_changed("[email protected]", 5) | ||
self.assertEqual( | ||
{"[email protected]", "[email protected]"}, set(cache._entity_to_key) | ||
) | ||
self.assertEqual( | ||
cache.get_all_entities_changed(3), | ||
cache.get_all_entities_changed(3).entities, | ||
["[email protected]", "[email protected]"], | ||
) | ||
self.assertIsNone(cache.get_all_entities_changed(2)) | ||
self.assertFalse(cache.get_all_entities_changed(2).hit) | ||
|
||
def test_get_all_entities_changed(self) -> None: | ||
""" | ||
|
@@ -105,10 +107,12 @@ def test_get_all_entities_changed(self) -> None: | |
# Results are ordered so either of these are valid. | ||
ok1 = ["[email protected]", "[email protected]", "[email protected]"] | ||
ok2 = ["[email protected]", "[email protected]", "[email protected]"] | ||
self.assertTrue(r == ok1 or r == ok2) | ||
self.assertTrue(r.entities == ok1 or r.entities == ok2) | ||
|
||
self.assertEqual(cache.get_all_entities_changed(3), ["[email protected]"]) | ||
self.assertEqual(cache.get_all_entities_changed(1), None) | ||
self.assertEqual( | ||
cache.get_all_entities_changed(3).entities, ["[email protected]"] | ||
) | ||
self.assertFalse(cache.get_all_entities_changed(1).hit) | ||
|
||
# ... later, things gest more updates | ||
cache.entity_has_changed("[email protected]", 5) | ||
|
@@ -128,7 +132,7 @@ def test_get_all_entities_changed(self) -> None: | |
"[email protected]", | ||
] | ||
r = cache.get_all_entities_changed(3) | ||
self.assertTrue(r == ok1 or r == ok2) | ||
self.assertTrue(r.entities == ok1 or r.entities == ok2) | ||
|
||
def test_has_any_entity_changed(self) -> None: | ||
""" | ||
|