@@ -359,6 +359,7 @@ def test_autodelete_photos(self) -> None:
359359 f"{ file_name } not expected, but present"
360360 )
361361
362+ @pytest .mark .skipif (constants .MAX_RETRIES == 0 , reason = "Disabled when MAX_RETRIES set to 0" )
362363 def test_retry_delete_after_download_session_error (self ) -> None :
363364 base_dir = os .path .join (self .fixtures_path , inspect .stack ()[0 ][3 ])
364365 cookie_dir = os .path .join (base_dir , "cookie" )
@@ -434,16 +435,24 @@ def mocked_authenticate(self: PyiCloudService) -> None:
434435 self ._caplog .text ,
435436 )
436437
437- # Error msg should be repeated 5 times
438+ # Error msg should be repeated always 1 time
438439 self .assertEqual (
439440 self ._caplog .text .count ("Session error, re-authenticating..." ),
440441 1 ,
441- "Re-auth message count" ,
442+ "retry count" ,
442443 )
443444
444- self .assertEqual (pa_delete .call_count , 2 , "delete call count" )
445- # Make sure we only call sleep 4 times (skip the first retry)
446- self .assertEqual (sleep_mock .call_count , 0 , "Sleep call count" )
445+ self .assertEqual (
446+ pa_delete .call_count ,
447+ 1 + min (1 , constants .MAX_RETRIES ),
448+ "delete call count" ,
449+ )
450+ # Make sure we only call sleep 0 times (skip the first retry)
451+ self .assertEqual (
452+ sleep_mock .call_count ,
453+ 0 ,
454+ "sleep count" ,
455+ )
447456 self .assertEqual (result .exit_code , 0 , "Exit code" )
448457
449458 # check files
@@ -529,19 +538,21 @@ def mocked_authenticate(self: PyiCloudService) -> None:
529538 self ._caplog .text ,
530539 )
531540
532- # Error msg should be repeated 5 times
541+ # Error msg should be repeated MAX_RETRIES times
533542 self .assertEqual (
534543 self ._caplog .text .count ("Session error, re-authenticating..." ),
535- constants .MAX_RETRIES ,
536- "Re-auth message count" ,
544+ max ( 1 , constants .MAX_RETRIES ) ,
545+ "retry count" ,
537546 )
538547
539548 self .assertEqual (
540549 pa_delete .call_count , constants .MAX_RETRIES + 1 , "delete call count"
541550 )
542- # Make sure we only call sleep 4 times (skip the first retry)
551+ # Make sure we only call sleep MAX_RETRIES-1 times (skip the first retry)
543552 self .assertEqual (
544- sleep_mock .call_count , constants .MAX_RETRIES - 1 , "Sleep call count"
553+ sleep_mock .call_count ,
554+ max (0 , constants .MAX_RETRIES - 1 ),
555+ "sleep count" ,
545556 )
546557 self .assertEqual (result .exit_code , 1 , "Exit code" )
547558
@@ -555,6 +566,7 @@ def mocked_authenticate(self: PyiCloudService) -> None:
555566
556567 assert sum (1 for _ in files_in_result ) == 1
557568
569+ @pytest .mark .skipif (constants .MAX_RETRIES == 0 , reason = "Disabled when MAX_RETRIES set to 0" )
558570 def test_retry_delete_after_download_internal_error (self ) -> None :
559571 base_dir = os .path .join (self .fixtures_path , inspect .stack ()[0 ][3 ])
560572 cookie_dir = os .path .join (base_dir , "cookie" )
@@ -616,16 +628,20 @@ def mock_raise_response_error(
616628 self ._caplog .text ,
617629 )
618630
619- # Error msg should be repeated 5 times
631+ # Error msg should be repeated MAX_RETRIES times
620632 self .assertEqual (
621633 self ._caplog .text .count ("Internal Error at Apple, retrying..." ),
622- 1 ,
623- "Retry message count" ,
634+ min ( 1 , constants . MAX_RETRIES ) ,
635+ "retry count" ,
624636 )
625637
626- self .assertEqual (pa_delete .call_count , 2 , "delete call count" )
638+ self .assertEqual (
639+ pa_delete .call_count , 1 + min (1 , constants .MAX_RETRIES ), "delete count"
640+ )
627641 # Make sure we only call sleep 4 times (skip the first retry)
628- self .assertEqual (sleep_mock .call_count , 1 , "Sleep call count" )
642+ self .assertEqual (
643+ sleep_mock .call_count , min (1 , constants .MAX_RETRIES ), "sleep count"
644+ )
629645 self .assertEqual (result .exit_code , 0 , "Exit code" )
630646
631647 # check files
@@ -701,16 +717,14 @@ def mock_raise_response_error(
701717 self .assertEqual (
702718 self ._caplog .text .count ("Internal Error at Apple, retrying..." ),
703719 constants .MAX_RETRIES ,
704- "Retry message count" ,
720+ "retry count" ,
705721 )
706722
707723 self .assertEqual (
708- pa_delete .call_count , constants .MAX_RETRIES + 1 , "delete call count"
724+ pa_delete .call_count , constants .MAX_RETRIES + 1 , "delete count"
709725 )
710726 # Make sure we only call sleep N times (skip the first retry)
711- self .assertEqual (
712- sleep_mock .call_count , constants .MAX_RETRIES , "Sleep call count"
713- )
727+ self .assertEqual (sleep_mock .call_count , constants .MAX_RETRIES , "sleep count" )
714728 self .assertEqual (result .exit_code , 1 , "Exit code" )
715729
716730 # check files
0 commit comments