|
1 | 1 | import pytest |
2 | 2 |
|
| 3 | +from copy import deepcopy |
| 4 | + |
3 | 5 | from sentry_sdk._lru_cache import LRUCache |
4 | 6 |
|
5 | 7 |
|
@@ -58,3 +60,29 @@ def test_cache_get_all(): |
58 | 60 | assert cache.get_all() == [(1, 1), (2, 2), (3, 3)] |
59 | 61 | cache.get(1) |
60 | 62 | assert cache.get_all() == [(2, 2), (3, 3), (1, 1)] |
| 63 | + |
| 64 | + |
| 65 | +def test_cache_copy(): |
| 66 | + cache = LRUCache(3) |
| 67 | + cache.set(0, 0) |
| 68 | + cache.set(1, 1) |
| 69 | + |
| 70 | + copied = deepcopy(cache) |
| 71 | + cache.set(2, 2) |
| 72 | + cache.set(3, 3) |
| 73 | + assert copied.get_all() == [(0, 0), (1, 1)] |
| 74 | + assert cache.get_all() == [(1, 1), (2, 2), (3, 3)] |
| 75 | + |
| 76 | + copied = deepcopy(cache) |
| 77 | + cache.get(1) |
| 78 | + assert copied.get_all() == [(1, 1), (2, 2), (3, 3)] |
| 79 | + assert cache.get_all() == [(2, 2), (3, 3), (1, 1)] |
| 80 | + |
| 81 | + |
| 82 | +def test_cache_pollution(): |
| 83 | + cache1 = LRUCache(max_size=2) |
| 84 | + cache1.set(1, True) |
| 85 | + cache2 = deepcopy(cache1) |
| 86 | + cache2.set(1, False) |
| 87 | + assert cache1.get(1) is True |
| 88 | + assert cache2.get(1) is False |
0 commit comments