Skip to content

Commit af2f8f1

Browse files
PR comments; rebased
1 parent 62a4a50 commit af2f8f1

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

tests/profiling/collector/test_asyncio.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import glob
44
import os
55
import sys
6+
from typing import Optional
67
import uuid
78

89
import pytest
910

1011
from ddtrace import ext
1112
from ddtrace.internal.datadog.profiling import ddup
1213
from ddtrace.profiling.collector import asyncio as collector_asyncio
14+
from ddtrace.profiling.collector._lock import _LockAllocatorWrapper as LockAllocatorWrapper
1315
from tests.profiling.collector import pprof_utils
1416
from tests.profiling.collector import test_collector
1517
from tests.profiling.collector.lock_utils import get_lock_linenos
@@ -53,28 +55,18 @@ def teardown_method(self):
5355

5456
async def test_subclassing_wrapped_lock(self) -> None:
5557
"""Test that subclassing of a wrapped lock type when profiling is active."""
56-
from typing import Optional
57-
58-
from ddtrace.profiling.collector._lock import _LockAllocatorWrapper
59-
6058
with collector_asyncio.AsyncioLockCollector(capture_pct=100):
61-
assert isinstance(asyncio.Lock, _LockAllocatorWrapper)
59+
assert isinstance(asyncio.Lock, LockAllocatorWrapper)
6260

6361
# This should NOT raise TypeError
6462
class CustomLock(asyncio.Lock): # type: ignore[misc]
6563
def __init__(self) -> None:
6664
super().__init__()
67-
self._owner: Optional[int] = None
68-
self._count: int = 0
6965

7066
# Verify subclassing and functionality
7167
custom_lock: CustomLock = CustomLock()
72-
assert hasattr(custom_lock, "_owner")
73-
assert hasattr(custom_lock, "_count")
74-
assert custom_lock._owner is None
75-
assert custom_lock._count == 0
7668

77-
# Test async acquire/release
69+
# Verify subclassing and functionality
7870
await custom_lock.acquire()
7971
assert custom_lock.locked()
8072
custom_lock.release()

tests/profiling/collector/test_threading.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,14 @@ def test_lock_repr(
173173

174174

175175
def test_patch():
176-
from ddtrace.profiling.collector._lock import _LockAllocatorWrapper
177-
178176
lock = threading.Lock
179177
collector = ThreadingLockCollector()
180178
collector.start()
181179
assert lock == collector._original_lock
182180
# After patching, threading.Lock is replaced with our wrapper
183181
# The old reference (lock) points to the original builtin Lock class
184182
assert lock != threading.Lock # They're different after patching
185-
assert isinstance(threading.Lock, _LockAllocatorWrapper) # threading.Lock is now wrapped
183+
assert isinstance(threading.Lock, LockAllocatorWrapper) # threading.Lock is now wrapped
186184
assert callable(threading.Lock) # and it's callable
187185
collector.stop()
188186
# After stopping, everything is restored
@@ -1396,22 +1394,16 @@ def test_subclassing_wrapped_lock(self) -> None:
13961394
threading.Lock and threading.RLock are C types that don't support subclassing
13971395
through __mro_entries__.
13981396
"""
1399-
from ddtrace.profiling.collector._lock import _LockAllocatorWrapper
1400-
14011397
with self.collector_class():
1402-
assert isinstance(self.lock_class, _LockAllocatorWrapper)
1398+
assert isinstance(self.lock_class, LockAllocatorWrapper)
14031399

14041400
# This should NOT raise TypeError
14051401
class CustomLock(self.lock_class): # type: ignore[misc]
14061402
def __init__(self) -> None:
14071403
super().__init__()
1408-
self.custom_attr: str = "test"
14091404

14101405
# Verify subclassing and functionality
14111406
custom_lock: CustomLock = CustomLock()
1412-
assert hasattr(custom_lock, "custom_attr")
1413-
assert custom_lock.custom_attr == "test"
1414-
14151407
assert custom_lock.acquire()
14161408
custom_lock.release()
14171409

0 commit comments

Comments
 (0)