@@ -360,6 +360,67 @@ def validate_and_cleanup() -> None:
360360 validate_and_cleanup ()
361361
362362
363+ @pytest .mark .subprocess (env = dict (DD_PROFILING_ENABLE_ASSERTS = "true" ))
364+ def test_assertion_error_raised_with_enable_asserts ():
365+ """Ensure that AssertionError is propagated when config.enable_asserts=True."""
366+ import threading
367+
368+ import mock
369+ import pytest
370+
371+ from ddtrace .internal .datadog .profiling import ddup
372+ from ddtrace .profiling .collector .threading import ThreadingLockCollector
373+
374+ # Initialize ddup (required before using collectors)
375+ assert ddup .is_available , "ddup is not available"
376+ ddup .config (env = "test" , service = "test_asserts" , version = "1.0" , output_filename = "/tmp/test_asserts" )
377+ ddup .start ()
378+
379+ with ThreadingLockCollector (capture_pct = 100 ):
380+ lock = threading .Lock ()
381+
382+ # Patch _maybe_update_self_name to raise AssertionError
383+ lock ._maybe_update_self_name = mock .Mock (side_effect = AssertionError ("test: unexpected frame in stack" ))
384+
385+ with pytest .raises (AssertionError ):
386+ # AssertionError should be propagated when enable_asserts=True
387+ lock .acquire ()
388+
389+
390+ @pytest .mark .subprocess (env = dict (DD_PROFILING_ENABLE_ASSERTS = "false" ))
391+ def test_all_exceptions_suppressed_by_default () -> None :
392+ """Ensure that exceptions are silently suppressed in the `_acquire` method when config.enable_asserts=False (default)."""
393+ import threading
394+
395+ import mock
396+
397+ from ddtrace .internal .datadog .profiling import ddup
398+ from ddtrace .profiling .collector .threading import ThreadingLockCollector
399+
400+ # Initialize ddup (required before using collectors)
401+ assert ddup .is_available , "ddup is not available"
402+ ddup .config (env = "test" , service = "test_exceptions" , version = "1.0" , output_filename = "/tmp/test_exceptions" )
403+ ddup .start ()
404+
405+ with ThreadingLockCollector (capture_pct = 100 ):
406+ lock = threading .Lock ()
407+
408+ # Patch _maybe_update_self_name to raise AssertionError
409+ lock ._maybe_update_self_name = mock .Mock (side_effect = AssertionError ("Unexpected frame in stack: 'fubar'" ))
410+ lock .acquire ()
411+ lock .release ()
412+
413+ # Patch _maybe_update_self_name to raise RuntimeError
414+ lock ._maybe_update_self_name = mock .Mock (side_effect = RuntimeError ("Some profiling error" ))
415+ lock .acquire ()
416+ lock .release ()
417+
418+ # Patch _maybe_update_self_name to raise Exception
419+ lock ._maybe_update_self_name = mock .Mock (side_effect = Exception ("Wut happened?!?!" ))
420+ lock .acquire ()
421+ lock .release ()
422+
423+
363424class BaseThreadingLockCollectorTest :
364425 # These should be implemented by child classes
365426 @property
@@ -979,32 +1040,6 @@ def test_upload_resets_profile(self) -> None:
9791040 with pytest .raises (AssertionError ):
9801041 pprof_utils .parse_newest_profile (self .output_filename )
9811042
982- def test_assertion_exceptions_raised_in_acquire (self ) -> None :
983- """Ensure that AssertionError exceptions is propagated in the `_acquire` method."""
984-
985- with self .collector_class (capture_pct = 100 ):
986- lock = self .lock_class ()
987-
988- # Patch _maybe_update_self_name to raise AssertionError
989- lock ._maybe_update_self_name = mock .Mock (side_effect = AssertionError ("test: unexpected frame in stack" ))
990-
991- with pytest .raises (AssertionError ):
992- # acquire() will propagate AssertionError if _maybe_update_self_name raises it
993- lock .acquire ()
994-
995- def test_non_assertion_exceptions_suppressed_in_acquire (self ) -> None :
996- """Ensure that non - AssertionError exceptions are silently suppressed in the `_acquire` method."""
997-
998- with self .collector_class (capture_pct = 100 ):
999- lock = self .lock_class ()
1000-
1001- # Patch _maybe_update_self_name to raise RuntimeError
1002- lock ._maybe_update_self_name = mock .Mock (side_effect = RuntimeError ("Some profiling error" ))
1003-
1004- # RuntimeError should be caught and suppressed - lock operations should succeed
1005- lock .acquire ()
1006- lock .release ()
1007-
10081043
10091044class TestThreadingLockCollector (BaseThreadingLockCollectorTest ):
10101045 """Test Lock profiling"""
0 commit comments