@@ -291,14 +291,65 @@ def test_container_task_timeout_k8s_serialization():
291291 sys .platform in ["darwin" , "win32" ],
292292 reason = "Skip if running on windows or macos due to CI Docker environment setup failure" ,
293293)
294- def test_container_task_within_timeout ():
295- ct_timedelta = ContainerTask (
296- name = "no-timeout-task" ,
297- input_data_dir = "/var/inputs" ,
298- output_data_dir = "/var/outputs" ,
294+ def test_container_task_timeout_in_metadata ():
295+ from flytekit .core .base_task import TaskMetadata
296+
297+ ct_with_timedelta = ContainerTask (
298+ name = "timeout-metadata-test" ,
299+ image = "busybox" ,
300+ command = ["echo" , "hello" ],
301+ timeout = timedelta (minutes = 5 ),
302+ )
303+
304+ assert ct_with_timedelta .metadata .timeout == timedelta (minutes = 5 )
305+
306+ # Test with custom metadata - timeout should be set in the provided metadata
307+ custom_metadata = TaskMetadata (retries = 3 )
308+ ct_with_custom_metadata = ContainerTask (
309+ name = "custom-metadata-timeout-test" ,
299310 image = "busybox" ,
300- command = ["sleep" , "1" ],
301- timeout = timedelta (seconds = 500 ),
311+ command = ["echo" , "hello" ],
312+ metadata = custom_metadata ,
313+ timeout = timedelta (seconds = 30 ),
302314 )
303315
304- ct_timedelta .execute ()
316+ # Verify timeout is set in the custom metadata and retries are preserved
317+ assert ct_with_custom_metadata .metadata .timeout == timedelta (seconds = 30 )
318+ assert ct_with_custom_metadata .metadata .retries == 3
319+
320+ ct_without_timeout = ContainerTask (
321+ name = "no-timeout-test" ,
322+ image = "busybox" ,
323+ command = ["echo" , "hello" ]
324+ )
325+
326+ assert ct_without_timeout .metadata .timeout is None
327+
328+
329+ def test_container_task_timeout_serialization ():
330+ ps = V1PodSpec (
331+ containers = [], tolerations = [V1Toleration (effect = "NoSchedule" , key = "nvidia.com/gpu" , operator = "Exists" )]
332+ )
333+ pt = PodTemplate (pod_spec = ps , labels = {"test" : "timeout" })
334+
335+ default_image = Image (name = "default" , fqn = "docker.io/xyz" , tag = "some-git-hash" )
336+ default_image_config = ImageConfig (default_image = default_image )
337+ default_serialization_settings = SerializationSettings (
338+ project = "p" , domain = "d" , version = "v" , image_config = default_image_config
339+ )
340+
341+ ct_with_timeout = ContainerTask (
342+ name = "timeout-serialization-test" ,
343+ image = "busybox" ,
344+ command = ["echo" , "hello" ],
345+ pod_template = pt ,
346+ timeout = timedelta (minutes = 10 ),
347+ )
348+
349+ from flytekit .tools .translator import get_serializable_task
350+ from collections import OrderedDict
351+
352+ serialized_task = get_serializable_task (OrderedDict (), default_serialization_settings , ct_with_timeout )
353+
354+ k8s_pod = ct_with_timeout .get_k8s_pod (default_serialization_settings )
355+ assert k8s_pod .pod_spec ["activeDeadlineSeconds" ] == 600 # 10 minutes in seconds
0 commit comments