1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
from sentry_sdk.flag_utils import FlagBuffer
def test_flag_tracking():
"""Assert the ring buffer works."""
buffer = FlagBuffer(capacity=3)
buffer.set("a", True)
flags = buffer.get()
assert len(flags) == 1
assert flags == [{"flag": "a", "result": True}]
buffer.set("b", True)
flags = buffer.get()
assert len(flags) == 2
assert flags == [{"flag": "a", "result": True}, {"flag": "b", "result": True}]
buffer.set("c", True)
flags = buffer.get()
assert len(flags) == 3
assert flags == [
{"flag": "a", "result": True},
{"flag": "b", "result": True},
{"flag": "c", "result": True},
]
buffer.set("d", False)
flags = buffer.get()
assert len(flags) == 3
assert flags == [
{"flag": "b", "result": True},
{"flag": "c", "result": True},
{"flag": "d", "result": False},
]
buffer.set("e", False)
buffer.set("f", False)
flags = buffer.get()
assert len(flags) == 3
assert flags == [
{"flag": "d", "result": False},
{"flag": "e", "result": False},
{"flag": "f", "result": False},
]
|