@@ -1057,6 +1057,87 @@ def test_janitor(sushi_context, mocker: MockerFixture) -> None:
10571057 )
10581058
10591059
1060+ @time_machine .travel ("2025-01-03 00:00:00 UTC" , tick = False )
1061+ def test_run_janitor_default_timestamp (sushi_context : Context , mocker : MockerFixture ) -> None :
1062+ context = sushi_context
1063+ mocker .patch .object (context .console , "start_cleanup" , return_value = True )
1064+ stop_cleanup = mocker .patch .object (context .console , "stop_cleanup" )
1065+ run_janitor = mocker .patch .object (context , "_run_janitor" )
1066+
1067+ result = context .run_janitor (ignore_ttl = False )
1068+
1069+ assert result is True
1070+ run_janitor .assert_called_once_with (False , current_ts = 1735862400000 )
1071+ stop_cleanup .assert_called_once_with (success = True )
1072+
1073+
1074+ @time_machine .travel ("2025-01-03 00:00:00 UTC" , tick = False )
1075+ def test_run_janitor_no_batch_size_seconds (sushi_context : Context , mocker : MockerFixture ) -> None :
1076+ context = sushi_context
1077+ mocker .patch .object (context .console , "start_cleanup" , return_value = True )
1078+ stop_cleanup = mocker .patch .object (context .console , "stop_cleanup" )
1079+ run_janitor = mocker .patch .object (context , "_run_janitor" )
1080+
1081+ result = context .run_janitor (
1082+ ignore_ttl = False ,
1083+ batch_start = "2 days ago" ,
1084+ )
1085+
1086+ assert result is True
1087+ assert run_janitor .call_args_list == [
1088+ call (False , current_ts = 1735689600000 ),
1089+ ]
1090+ stop_cleanup .assert_called_once_with (success = True )
1091+
1092+
1093+ @time_machine .travel ("2025-01-03 00:00:00 UTC" , tick = False )
1094+ def test_run_janitor_batches (sushi_context : Context , mocker : MockerFixture ) -> None :
1095+ context = sushi_context
1096+ mocker .patch .object (context .console , "start_cleanup" , return_value = True )
1097+ stop_cleanup = mocker .patch .object (context .console , "stop_cleanup" )
1098+ run_janitor = mocker .patch .object (context , "_run_janitor" )
1099+
1100+ result = context .run_janitor (
1101+ ignore_ttl = False ,
1102+ batch_start = "2 days ago" ,
1103+ batch_size_seconds = 60 * 60 * 24 , # 1 day
1104+ )
1105+
1106+ assert result is True
1107+ assert run_janitor .call_args_list == [
1108+ call (False , current_ts = 1735689600000 ),
1109+ call (False , current_ts = 1735776000000 ),
1110+ call (False , current_ts = 1735862400000 ),
1111+ ]
1112+ stop_cleanup .assert_called_once_with (success = True )
1113+
1114+
1115+ def test_run_janitor_batch_requires_current_ts (
1116+ sushi_context : Context , mocker : MockerFixture
1117+ ) -> None :
1118+ context = sushi_context
1119+ mocker .patch .object (context .console , "start_cleanup" , return_value = True )
1120+ stop_cleanup = mocker .patch .object (context .console , "stop_cleanup" )
1121+
1122+ with pytest .raises (SQLMeshError , match = "batch_start must be provided" ):
1123+ context .run_janitor (ignore_ttl = False , batch_size_seconds = 60 )
1124+
1125+ stop_cleanup .assert_called_once_with (success = False )
1126+
1127+
1128+ def test_run_janitor_batch_requires_positive_seconds (
1129+ sushi_context : Context , mocker : MockerFixture
1130+ ) -> None :
1131+ context = sushi_context
1132+ mocker .patch .object (context .console , "start_cleanup" , return_value = True )
1133+ stop_cleanup = mocker .patch .object (context .console , "stop_cleanup" )
1134+
1135+ with pytest .raises (SQLMeshError , match = "positive integer" ):
1136+ context .run_janitor (ignore_ttl = False , batch_start = 100 , batch_size_seconds = 0 )
1137+
1138+ stop_cleanup .assert_called_once_with (success = False )
1139+
1140+
10601141@pytest .mark .slow
10611142def test_plan_default_end (sushi_context_pre_scheduling : Context ):
10621143 prod_plan_builder = sushi_context_pre_scheduling .plan_builder ("prod" )
0 commit comments