Skip to content

Commit 4c62a2c

Browse files
fix lint
1 parent a7fb6e2 commit 4c62a2c

File tree

2 files changed

+68
-155
lines changed

2 files changed

+68
-155
lines changed

β€ŽRLOCK_E2E_VALIDATION.mdβ€Ž

Lines changed: 0 additions & 96 deletions
This file was deleted.

β€Žtest_rlock_e2e.pyβ€Ž

Lines changed: 68 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,47 @@
44
Validates RLock collector functionality and integration points.
55
"""
66

7-
import threading
87
import sys
9-
import os
8+
import threading
109
import time
1110

11+
1212
# Add the project to Python path
13-
sys.path.insert(0, '/Users/vlad.scherbich/go/src/github.com/DataDog/dd-trace-py-2')
13+
sys.path.insert(0, "/Users/vlad.scherbich/go/src/github.com/DataDog/dd-trace-py-2")
14+
1415

1516
def test_rlock_import_and_creation():
1617
"""Test that RLock collector can be imported and created"""
1718
print("=== RLock Import and Creation Test ===")
18-
19+
1920
try:
2021
from ddtrace.profiling.collector import threading as collector_threading
22+
2123
print("βœ… Successfully imported ThreadingRLockCollector")
22-
24+
2325
# Create collectors
2426
lock_collector = collector_threading.ThreadingLockCollector()
2527
rlock_collector = collector_threading.ThreadingRLockCollector()
26-
28+
2729
print(f"βœ… Lock collector created: {type(lock_collector)}")
2830
print(f"βœ… RLock collector created: {type(rlock_collector)}")
29-
31+
3032
return True
31-
33+
3234
except Exception as e:
3335
print(f"❌ Import/creation failed: {e}")
3436
return False
3537

38+
3639
def test_rlock_behavior_patterns():
3740
"""Test RLock reentrant behavior patterns (without profiler active)"""
3841
print("\n=== RLock Behavior Patterns Test ===")
39-
42+
4043
try:
4144
# Test standard RLock reentrant behavior
4245
rlock = threading.RLock()
4346
results = []
44-
47+
4548
def test_reentrant_pattern():
4649
"""Test multi-level reentrant acquisition"""
4750
with rlock:
@@ -51,51 +54,52 @@ def test_reentrant_pattern():
5154
with rlock: # Double reentrant
5255
results.append("Level 3")
5356
time.sleep(0.01)
54-
57+
5558
# Test with multiple threads
5659
threads = []
5760
for i in range(2):
5861
t = threading.Thread(target=test_reentrant_pattern, name=f"Thread-{i}")
5962
threads.append(t)
60-
63+
6164
for t in threads:
6265
t.start()
63-
66+
6467
for t in threads:
6568
t.join()
66-
69+
6770
expected_results = 2 * 3 # 2 threads Γ— 3 levels each
6871
print(f"Completed {len(results)} reentrant operations")
6972
print(f"Expected {expected_results} operations")
70-
73+
7174
success = len(results) == expected_results
7275
if success:
7376
print("βœ… RLock reentrant behavior works correctly!")
7477
else:
7578
print(f"⚠️ Unexpected result count: {len(results)} vs {expected_results}")
76-
79+
7780
return success
78-
81+
7982
except Exception as e:
8083
print(f"❌ RLock behavior test failed: {e}")
8184
return False
8285

86+
8387
def test_lock_vs_rlock_differences():
8488
"""Test the key differences between Lock and RLock"""
8589
print("\n=== Lock vs RLock Differences Test ===")
86-
90+
8791
try:
8892
lock = threading.Lock()
8993
rlock = threading.RLock()
90-
94+
9195
print(f"Lock type: {type(lock)}")
9296
print(f"RLock type: {type(rlock)}")
93-
97+
9498
# Test Lock (non-reentrant)
9599
print("Testing Lock (non-reentrant)...")
96100
with lock:
97101
print(" Lock acquired and released successfully")
98-
102+
99103
# Test RLock (reentrant)
100104
print("Testing RLock (reentrant)...")
101105
with rlock:
@@ -107,116 +111,120 @@ def test_lock_vs_rlock_differences():
107111
print(" RLock level 3 released")
108112
print(" RLock level 2 released")
109113
print(" RLock level 1 released")
110-
114+
111115
print("βœ… Lock vs RLock behavior differences confirmed!")
112116
return True
113-
117+
114118
except Exception as e:
115119
print(f"❌ Lock vs RLock test failed: {e}")
116120
return False
117121

122+
118123
def test_threading_module_integration():
119124
"""Test integration with threading module"""
120125
print("\n=== Threading Module Integration Test ===")
121-
126+
122127
try:
123128
# Verify we can create locks normally
124129
locks_created = []
125-
130+
126131
# Create various lock types
127132
regular_lock = threading.Lock()
128133
reentrant_lock = threading.RLock()
129134
condition = threading.Condition()
130135
semaphore = threading.Semaphore()
131-
132-
locks_created.extend([
133-
("Lock", regular_lock),
134-
("RLock", reentrant_lock),
135-
("Condition", condition),
136-
("Semaphore", semaphore)
137-
])
138-
136+
137+
locks_created.extend(
138+
[("Lock", regular_lock), ("RLock", reentrant_lock), ("Condition", condition), ("Semaphore", semaphore)]
139+
)
140+
139141
print("Created lock types:")
140142
for name, lock_obj in locks_created:
141143
print(f" {name}: {type(lock_obj)}")
142-
144+
143145
# Test basic functionality
144146
print("Testing basic functionality...")
145-
147+
146148
with regular_lock:
147149
print(" Regular Lock works")
148-
150+
149151
with reentrant_lock:
150152
with reentrant_lock: # Reentrant
151153
print(" RLock reentrant functionality works")
152-
154+
153155
with condition:
154156
print(" Condition works")
155-
157+
156158
with semaphore:
157159
print(" Semaphore works")
158-
160+
159161
print("βœ… Threading module integration successful!")
160162
return True
161-
163+
162164
except Exception as e:
163165
print(f"❌ Threading integration test failed: {e}")
164166
return False
165167

168+
166169
def test_profiler_readiness():
167170
"""Test that the environment is ready for profiling"""
168171
print("\n=== Profiler Readiness Test ===")
169-
172+
170173
try:
171174
# Test imports
172-
import ddtrace
175+
import ddtrace # noqa: F401
176+
173177
print("βœ… ddtrace imports successfully")
174-
178+
175179
from ddtrace.profiling.collector import threading as collector_threading
180+
176181
print("βœ… Threading collector imports successfully")
177-
178-
from ddtrace.profiling.collector import _lock
182+
183+
from ddtrace.profiling.collector import _lock # noqa: F401
184+
179185
print("βœ… Lock collector base imports successfully")
180-
186+
181187
# Test collector classes exist
182188
lock_collector_class = collector_threading.ThreadingLockCollector
183189
rlock_collector_class = collector_threading.ThreadingRLockCollector
184-
190+
185191
print(f"βœ… Lock collector class: {lock_collector_class}")
186192
print(f"βœ… RLock collector class: {rlock_collector_class}")
187-
193+
188194
# Test profiled lock classes exist
189195
profiled_lock_class = collector_threading._ProfiledThreadingLock
190196
profiled_rlock_class = collector_threading._ProfiledThreadingRLock
191-
197+
192198
print(f"βœ… Profiled Lock class: {profiled_lock_class}")
193199
print(f"βœ… Profiled RLock class: {profiled_rlock_class}")
194-
200+
195201
print("βœ… Environment is ready for RLock profiling!")
196202
return True
197-
203+
198204
except Exception as e:
199205
print(f"❌ Profiler readiness test failed: {e}")
200206
import traceback
207+
201208
traceback.print_exc()
202209
return False
203210

211+
204212
if __name__ == "__main__":
205213
print("πŸ”’ E2E RLock Profiling Validation")
206214
print("=" * 50)
207215
print("This test validates RLock profiling integration")
208216
print("and core functionality.")
209217
print("=" * 50)
210218
print()
211-
219+
212220
try:
213221
# Run test suites
214222
test1_passed = test_rlock_import_and_creation()
215223
test2_passed = test_rlock_behavior_patterns()
216224
test3_passed = test_lock_vs_rlock_differences()
217225
test4_passed = test_threading_module_integration()
218226
test5_passed = test_profiler_readiness()
219-
227+
220228
print(f"\n{'=' * 50}")
221229
print("🏁 FINAL RESULTS")
222230
print(f"{'=' * 50}")
@@ -225,19 +233,20 @@ def test_profiler_readiness():
225233
print(f"Lock vs RLock differences: {'βœ… PASS' if test3_passed else '❌ FAIL'}")
226234
print(f"Threading module integration: {'βœ… PASS' if test4_passed else '❌ FAIL'}")
227235
print(f"Profiler readiness: {'βœ… PASS' if test5_passed else '❌ FAIL'}")
228-
236+
229237
all_passed = all([test1_passed, test2_passed, test3_passed, test4_passed, test5_passed])
230-
238+
231239
if all_passed:
232-
print(f"\nπŸŽ‰ ALL E2E TESTS PASSED!")
240+
print("\nπŸŽ‰ ALL E2E TESTS PASSED!")
233241
print("RLock profiling implementation is ready!")
234242
else:
235-
print(f"\n⚠️ Some tests had issues.")
236-
243+
print("\n⚠️ Some tests had issues.")
244+
237245
print(f"\n{'=' * 50}")
238246
print("E2E validation complete!")
239-
247+
240248
except Exception as e:
241249
print(f"\nπŸ’₯ Tests failed with exception: {e}")
242250
import traceback
251+
243252
traceback.print_exc()

0 commit comments

Comments
Β (0)