|
4 | 4 | import pytest |
5 | 5 |
|
6 | 6 | import sentry_sdk |
7 | | -from sentry_sdk.feature_flags import add_feature_flag |
| 7 | +from sentry_sdk.feature_flags import add_feature_flag, FlagBuffer |
8 | 8 |
|
9 | 9 |
|
10 | 10 | def test_featureflags_integration(sentry_init, capture_events, uninstall_integration): |
@@ -125,3 +125,45 @@ async def runner(): |
125 | 125 | {"flag": "world", "result": False}, |
126 | 126 | ] |
127 | 127 | } |
| 128 | + |
| 129 | + |
| 130 | +def test_flag_tracking(): |
| 131 | + """Assert the ring buffer works.""" |
| 132 | + buffer = FlagBuffer(capacity=3) |
| 133 | + buffer.set("a", True) |
| 134 | + flags = buffer.get() |
| 135 | + assert len(flags) == 1 |
| 136 | + assert flags == [{"flag": "a", "result": True}] |
| 137 | + |
| 138 | + buffer.set("b", True) |
| 139 | + flags = buffer.get() |
| 140 | + assert len(flags) == 2 |
| 141 | + assert flags == [{"flag": "a", "result": True}, {"flag": "b", "result": True}] |
| 142 | + |
| 143 | + buffer.set("c", True) |
| 144 | + flags = buffer.get() |
| 145 | + assert len(flags) == 3 |
| 146 | + assert flags == [ |
| 147 | + {"flag": "a", "result": True}, |
| 148 | + {"flag": "b", "result": True}, |
| 149 | + {"flag": "c", "result": True}, |
| 150 | + ] |
| 151 | + |
| 152 | + buffer.set("d", False) |
| 153 | + flags = buffer.get() |
| 154 | + assert len(flags) == 3 |
| 155 | + assert flags == [ |
| 156 | + {"flag": "b", "result": True}, |
| 157 | + {"flag": "c", "result": True}, |
| 158 | + {"flag": "d", "result": False}, |
| 159 | + ] |
| 160 | + |
| 161 | + buffer.set("e", False) |
| 162 | + buffer.set("f", False) |
| 163 | + flags = buffer.get() |
| 164 | + assert len(flags) == 3 |
| 165 | + assert flags == [ |
| 166 | + {"flag": "d", "result": False}, |
| 167 | + {"flag": "e", "result": False}, |
| 168 | + {"flag": "f", "result": False}, |
| 169 | + ] |
0 commit comments