@@ -1166,6 +1166,41 @@ def test_auto_cleanup_invalid(tmp_path):
11661166 assert len (dataset .versions ()) == 4
11671167
11681168
1169+ def test_enable_disable_auto_cleanup (tmp_path ):
1170+ table = pa .Table .from_pydict ({"a" : range (100 ), "b" : range (100 )})
1171+ base_dir = tmp_path / "test"
1172+ ds = lance .write_dataset (table , base_dir , mode = "create" )
1173+ auto_cleanup_options = AutoCleanupConfig (
1174+ interval = 1 ,
1175+ older_than_seconds = 1 ,
1176+ )
1177+ # enable auto cleanup
1178+ ds .optimize .enable_auto_cleanup (auto_cleanup_options )
1179+ lance .write_dataset (table , base_dir , mode = "append" )
1180+ lance .write_dataset (table , base_dir , mode = "append" )
1181+ lance .write_dataset (table , base_dir , mode = "append" )
1182+
1183+ time .sleep (5 )
1184+
1185+ # trigger cleanup
1186+ lance .write_dataset (table , base_dir , mode = "append" )
1187+ assert len (ds .versions ()) == 2
1188+
1189+ # this is a transactional commit, so will increase a version
1190+ ds .optimize .disable_auto_cleanup ()
1191+
1192+ lance .write_dataset (table , base_dir , mode = "append" )
1193+ lance .write_dataset (table , base_dir , mode = "append" )
1194+ lance .write_dataset (table , base_dir , mode = "append" )
1195+
1196+ time .sleep (5 )
1197+
1198+ # wait to see if cleanup would be trigger
1199+ lance .write_dataset (table , base_dir , mode = "append" )
1200+
1201+ assert len (ds .versions ()) == 7
1202+
1203+
11691204def test_create_from_commit (tmp_path : Path ):
11701205 table = pa .Table .from_pydict ({"a" : range (100 ), "b" : range (100 )})
11711206 base_dir = tmp_path / "test"
0 commit comments