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