@@ -548,9 +548,9 @@ def test_sort_options(self):
548548 mock_sample .assert_called_once ()
549549 mock_sample .reset_mock ()
550550
551- def test_async_aware_argument_all (self ):
552- """Test --async-aware all argument is parsed correctly ."""
553- test_args = ["profiling.sampling.cli" , "attach" , "12345" , "--async-aware" , "all" ]
551+ def test_async_aware_flag_defaults_to_running (self ):
552+ """Test --async-aware flag enables async profiling with default 'running' mode ."""
553+ test_args = ["profiling.sampling.cli" , "attach" , "12345" , "--async-aware" ]
554554
555555 with (
556556 mock .patch ("sys.argv" , test_args ),
@@ -560,13 +560,13 @@ def test_async_aware_argument_all(self):
560560 main ()
561561
562562 mock_sample .assert_called_once ()
563- # Verify async_aware was passed
563+ # Verify async_aware was passed with default "running" mode
564564 call_kwargs = mock_sample .call_args [1 ]
565- self .assertEqual (call_kwargs .get ("async_aware" ), "all " )
565+ self .assertEqual (call_kwargs .get ("async_aware" ), "running " )
566566
567- def test_async_aware_argument_running (self ):
568- """Test --async-aware running argument is parsed correctly ."""
569- test_args = ["profiling.sampling.cli" , "attach" , "12345" , "--async-aware" , "running " ]
567+ def test_async_aware_with_async_mode_all (self ):
568+ """Test --async-aware with --async-mode all ."""
569+ test_args = ["profiling.sampling.cli" , "attach" , "12345" , "--async-aware" , "--async-mode" , "all " ]
570570
571571 with (
572572 mock .patch ("sys.argv" , test_args ),
@@ -577,10 +577,10 @@ def test_async_aware_argument_running(self):
577577
578578 mock_sample .assert_called_once ()
579579 call_kwargs = mock_sample .call_args [1 ]
580- self .assertEqual (call_kwargs .get ("async_aware" ), "running " )
580+ self .assertEqual (call_kwargs .get ("async_aware" ), "all " )
581581
582582 def test_async_aware_default_is_none (self ):
583- """Test --async-aware defaults to None when not specified."""
583+ """Test async_aware defaults to None when --async-aware not specified."""
584584 test_args = ["profiling.sampling.cli" , "attach" , "12345" ]
585585
586586 with (
@@ -594,9 +594,9 @@ def test_async_aware_default_is_none(self):
594594 call_kwargs = mock_sample .call_args [1 ]
595595 self .assertIsNone (call_kwargs .get ("async_aware" ))
596596
597- def test_async_aware_invalid_choice (self ):
598- """Test --async-aware with invalid choice raises error."""
599- test_args = ["profiling.sampling.cli" , "attach" , "12345" , "--async-aware" , "invalid" ]
597+ def test_async_mode_invalid_choice (self ):
598+ """Test --async-mode with invalid choice raises error."""
599+ test_args = ["profiling.sampling.cli" , "attach" , "12345" , "--async-aware" , "--async-mode" , " invalid" ]
600600
601601 with (
602602 mock .patch ("sys.argv" , test_args ),
@@ -608,9 +608,25 @@ def test_async_aware_invalid_choice(self):
608608
609609 self .assertEqual (cm .exception .code , 2 ) # argparse error
610610
611+ def test_async_mode_requires_async_aware (self ):
612+ """Test --async-mode without --async-aware raises error."""
613+ test_args = ["profiling.sampling.cli" , "attach" , "12345" , "--async-mode" , "all" ]
614+
615+ with (
616+ mock .patch ("sys.argv" , test_args ),
617+ mock .patch ("sys.stderr" , io .StringIO ()) as mock_stderr ,
618+ self .assertRaises (SystemExit ) as cm ,
619+ ):
620+ from profiling .sampling .cli import main
621+ main ()
622+
623+ self .assertEqual (cm .exception .code , 2 ) # argparse error
624+ error_msg = mock_stderr .getvalue ()
625+ self .assertIn ("--async-mode requires --async-aware" , error_msg )
626+
611627 def test_async_aware_incompatible_with_native (self ):
612628 """Test --async-aware is incompatible with --native."""
613- test_args = ["profiling.sampling.cli" , "attach" , "12345" , "--async-aware" , "all" , " --native" ]
629+ test_args = ["profiling.sampling.cli" , "attach" , "12345" , "--async-aware" , "--native" ]
614630
615631 with (
616632 mock .patch ("sys.argv" , test_args ),
@@ -627,7 +643,7 @@ def test_async_aware_incompatible_with_native(self):
627643
628644 def test_async_aware_incompatible_with_no_gc (self ):
629645 """Test --async-aware is incompatible with --no-gc."""
630- test_args = ["profiling.sampling.cli" , "attach" , "12345" , "--async-aware" , "running" , " --no-gc" ]
646+ test_args = ["profiling.sampling.cli" , "attach" , "12345" , "--async-aware" , "--no-gc" ]
631647
632648 with (
633649 mock .patch ("sys.argv" , test_args ),
@@ -644,7 +660,7 @@ def test_async_aware_incompatible_with_no_gc(self):
644660
645661 def test_async_aware_incompatible_with_both_native_and_no_gc (self ):
646662 """Test --async-aware is incompatible with both --native and --no-gc."""
647- test_args = ["profiling.sampling.cli" , "attach" , "12345" , "--async-aware" , "all" , " --native" , "--no-gc" ]
663+ test_args = ["profiling.sampling.cli" , "attach" , "12345" , "--async-aware" , "--native" , "--no-gc" ]
648664
649665 with (
650666 mock .patch ("sys.argv" , test_args ),
@@ -662,7 +678,7 @@ def test_async_aware_incompatible_with_both_native_and_no_gc(self):
662678
663679 def test_async_aware_incompatible_with_mode (self ):
664680 """Test --async-aware is incompatible with --mode (non-wall)."""
665- test_args = ["profiling.sampling.cli" , "attach" , "12345" , "--async-aware" , "all" , " --mode" , "cpu" ]
681+ test_args = ["profiling.sampling.cli" , "attach" , "12345" , "--async-aware" , "--mode" , "cpu" ]
666682
667683 with (
668684 mock .patch ("sys.argv" , test_args ),
@@ -679,7 +695,7 @@ def test_async_aware_incompatible_with_mode(self):
679695
680696 def test_async_aware_incompatible_with_all_threads (self ):
681697 """Test --async-aware is incompatible with --all-threads."""
682- test_args = ["profiling.sampling.cli" , "attach" , "12345" , "--async-aware" , "running" , " --all-threads" ]
698+ test_args = ["profiling.sampling.cli" , "attach" , "12345" , "--async-aware" , "--all-threads" ]
683699
684700 with (
685701 mock .patch ("sys.argv" , test_args ),
0 commit comments