|
20 | 20 | from ddtrace._trace.span import Span |
21 | 21 | from ddtrace._trace.tracer import Tracer |
22 | 22 | from ddtrace.internal.datadog.profiling import ddup |
| 23 | +from ddtrace.profiling.collector._lock import _LockAllocatorWrapper as LockAllocatorWrapper |
23 | 24 | from ddtrace.profiling.collector.threading import ThreadingBoundedSemaphoreCollector |
24 | 25 | from ddtrace.profiling.collector.threading import ThreadingLockCollector |
25 | 26 | from ddtrace.profiling.collector.threading import ThreadingRLockCollector |
@@ -171,16 +172,14 @@ def test_lock_repr( |
171 | 172 |
|
172 | 173 |
|
173 | 174 | def test_patch(): |
174 | | - from ddtrace.profiling.collector._lock import _LockAllocatorWrapper |
175 | | - |
176 | 175 | lock = threading.Lock |
177 | 176 | collector = ThreadingLockCollector() |
178 | 177 | collector.start() |
179 | 178 | assert lock == collector._original_lock |
180 | 179 | # After patching, threading.Lock is replaced with our wrapper |
181 | 180 | # The old reference (lock) points to the original builtin Lock class |
182 | 181 | assert lock != threading.Lock # They're different after patching |
183 | | - assert isinstance(threading.Lock, _LockAllocatorWrapper) # threading.Lock is now wrapped |
| 182 | + assert isinstance(threading.Lock, LockAllocatorWrapper) # threading.Lock is now wrapped |
184 | 183 | assert callable(threading.Lock) # and it's callable |
185 | 184 | collector.stop() |
186 | 185 | # After stopping, everything is restored |
@@ -1385,22 +1384,16 @@ def test_subclassing_wrapped_lock(self) -> None: |
1385 | 1384 | threading.Lock and threading.RLock are C types that don't support subclassing |
1386 | 1385 | through __mro_entries__. |
1387 | 1386 | """ |
1388 | | - from ddtrace.profiling.collector._lock import _LockAllocatorWrapper |
1389 | | - |
1390 | 1387 | with self.collector_class(): |
1391 | | - assert isinstance(self.lock_class, _LockAllocatorWrapper) |
| 1388 | + assert isinstance(self.lock_class, LockAllocatorWrapper) |
1392 | 1389 |
|
1393 | 1390 | # This should NOT raise TypeError |
1394 | 1391 | class CustomLock(self.lock_class): # type: ignore[misc] |
1395 | 1392 | def __init__(self) -> None: |
1396 | 1393 | super().__init__() |
1397 | | - self.custom_attr: str = "test" |
1398 | 1394 |
|
1399 | 1395 | # Verify subclassing and functionality |
1400 | 1396 | custom_lock: CustomLock = CustomLock() |
1401 | | - assert hasattr(custom_lock, "custom_attr") |
1402 | | - assert custom_lock.custom_attr == "test" |
1403 | | - |
1404 | 1397 | assert custom_lock.acquire() |
1405 | 1398 | custom_lock.release() |
1406 | 1399 |
|
|
0 commit comments