@@ -800,11 +800,26 @@ def test_runopts(self) -> None:
800800 },
801801 )
802802
803- @patch ("kubernetes.client.CustomObjectsApi.delete_namespaced_custom_object" )
804- def test_cancel_existing (self , delete_namespaced_custom_object : MagicMock ) -> None :
803+ @patch ("kubernetes.client.CustomObjectsApi.get_namespaced_custom_object" )
804+ @patch ("kubernetes.client.CustomObjectsApi.replace_namespaced_custom_object_status" )
805+ def test_cancel_existing (
806+ self ,
807+ replace_namespaced_custom_object_status : MagicMock ,
808+ get_namespaced_custom_object : MagicMock ,
809+ ) -> None :
805810 scheduler = create_scheduler ("test" )
811+ get_namespaced_custom_object .return_value = {
812+ "status" : {"state" : {"phase" : "Running" }}
813+ }
806814 scheduler ._cancel_existing ("testnamespace:testjob" )
807- call = delete_namespaced_custom_object .call_args
815+ get_namespaced_custom_object .assert_called_once_with (
816+ group = "batch.volcano.sh" ,
817+ version = "v1alpha1" ,
818+ namespace = "testnamespace" ,
819+ plural = "jobs" ,
820+ name = "testjob" ,
821+ )
822+ call = replace_namespaced_custom_object_status .call_args
808823 args , kwargs = call
809824 self .assertEqual (
810825 kwargs ,
@@ -814,9 +829,26 @@ def test_cancel_existing(self, delete_namespaced_custom_object: MagicMock) -> No
814829 "namespace" : "testnamespace" ,
815830 "plural" : "jobs" ,
816831 "name" : "testjob" ,
832+ "body" : {"status" : {"state" : {"phase" : "Aborted" }}},
817833 },
818834 )
819835
836+ @patch ("kubernetes.client.CustomObjectsApi.delete_namespaced_custom_object" )
837+ @patch ("torchx.schedulers.kubernetes_scheduler.KubernetesScheduler.exists" )
838+ def test_delete (
839+ self , exists : MagicMock , delete_namespaced_custom_object : MagicMock
840+ ) -> None :
841+ scheduler = create_scheduler ("test" )
842+ exists .return_value = True
843+ scheduler .delete ("testnamespace:testjob" )
844+ delete_namespaced_custom_object .assert_called_once_with (
845+ group = "batch.volcano.sh" ,
846+ version = "v1alpha1" ,
847+ namespace = "testnamespace" ,
848+ plural = "jobs" ,
849+ name = "testjob" ,
850+ )
851+
820852 @patch ("kubernetes.client.CustomObjectsApi.list_namespaced_custom_object" )
821853 def test_list (self , list_namespaced_custom_object : MagicMock ) -> None :
822854 with patch (
0 commit comments