Skip to content

Commit 7edca64

Browse files
committed
Add coverage for the flag buffer on scope fork
1 parent 80fccd6 commit 7edca64

File tree

3 files changed

+18
-29
lines changed

3 files changed

+18
-29
lines changed

sentry_sdk/scope.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import sys
33
import warnings
4-
from copy import copy
4+
from copy import copy, deepcopy
55
from collections import deque
66
from contextlib import contextmanager
77
from enum import Enum
@@ -252,7 +252,7 @@ def __copy__(self):
252252

253253
rv._last_event_id = self._last_event_id
254254

255-
rv._flags = copy(self._flags)
255+
rv._flags = deepcopy(self._flags)
256256

257257
return rv
258258

tests/test_lru_cache.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import pytest
2-
from copy import copy
32

43
from sentry_sdk._lru_cache import LRUCache
54

@@ -59,29 +58,3 @@ def test_cache_get_all():
5958
assert cache.get_all() == [(1, 1), (2, 2), (3, 3)]
6059
cache.get(1)
6160
assert cache.get_all() == [(2, 2), (3, 3), (1, 1)]
62-
63-
64-
def test_cache_copy():
65-
cache = LRUCache(3)
66-
cache.set(0, 0)
67-
cache.set(1, 1)
68-
69-
copied = copy(cache)
70-
cache.set(2, 2)
71-
cache.set(3, 3)
72-
assert copied.get_all() == [(0, 0), (1, 1)]
73-
assert cache.get_all() == [(1, 1), (2, 2), (3, 3)]
74-
75-
copied = copy(cache)
76-
cache.get(1)
77-
assert copied.get_all() == [(1, 1), (2, 2), (3, 3)]
78-
assert cache.get_all() == [(2, 2), (3, 3), (1, 1)]
79-
80-
81-
def test_cache_no_overwrites_to_parent():
82-
cache1 = LRUCache(max_size=2)
83-
cache1.set(1, True)
84-
cache2 = cache1.__copy__()
85-
cache2.set(1, False)
86-
assert cache1.get(1) is True
87-
assert cache2.get(1) is False

tests/test_scope.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ def test_all_slots_copied():
4343
assert getattr(scope_copy, attr) == getattr(scope, attr)
4444

4545

46+
def test_scope_flags_copy():
47+
# A scope exists and a flag is appended to it.
48+
old_scope = Scope()
49+
old_scope.flags.set("a", True)
50+
51+
# Scope is forked; flag buffer is copied and contains the data of
52+
# the parent. The flag is overwritten.
53+
new_scope = old_scope.fork()
54+
new_scope.flags.set("a", False)
55+
56+
# New scope has the change. Old scope was not polluted by changes
57+
# to the new scope.
58+
old_scope.flags.get() == [{"flag": "a", "result": True}]
59+
new_scope.flags.get() == [{"flag": "a", "result": False}]
60+
61+
4662
def test_merging(sentry_init, capture_events):
4763
sentry_init()
4864

0 commit comments

Comments
 (0)