1+ import inspect
2+ import time
13import unittest
24
5+ from iwf .client import Client
6+ from iwf .iwf_api .models import IDReusePolicy
37from iwf .iwf_api .models import (
48 PersistenceLoadingPolicy ,
59 PersistenceLoadingType ,
610 WorkflowStateOptions as IdlWorkflowStateOptions ,
11+ RetryPolicy ,
12+ WaitUntilApiFailurePolicy ,
713)
8-
14+ from iwf .tests .worker_server import registry
15+ from iwf .tests .workflows .state_options_workflow import (
16+ StateOptionsWorkflow1 ,
17+ StateOptionsWorkflow2 ,
18+ )
19+ from iwf .workflow_options import WorkflowOptions
920from iwf .workflow_state_options import WorkflowStateOptions , _to_idl_state_options
21+ from ..errors import WorkflowFailed
1022
1123
1224class TestWorkflowStateOptions (unittest .TestCase ):
25+ @classmethod
26+ def setUpClass (cls ):
27+ cls .client = Client (registry )
28+
1329 def test_convert_to_idl (self ):
1430 empty_idl = IdlWorkflowStateOptions ()
1531 assert empty_idl == _to_idl_state_options (False , None , {})
@@ -29,3 +45,65 @@ def test_convert_to_idl(self):
2945 assert non_empty_idl == _to_idl_state_options (True , non_empty , {})
3046 non_empty .state_id = "state-id-2"
3147 assert non_empty .state_id == "state-id-2"
48+
49+ """Test that proceed_to_execute_when_wait_until_retry_exhausted correctly handles both enum values."""
50+
51+ def test_proceed_to_execute_when_wait_until_retry_exhausted (self ):
52+ retry_policy = RetryPolicy (maximum_attempts = 1 )
53+
54+ # Test PROCEED_ON_FAILURE
55+ options_proceed = WorkflowStateOptions (
56+ proceed_to_execute_when_wait_until_retry_exhausted = WaitUntilApiFailurePolicy .PROCEED_ON_FAILURE ,
57+ wait_until_api_retry_policy = retry_policy ,
58+ )
59+ result_proceed = _to_idl_state_options (False , options_proceed , {})
60+ assert (
61+ result_proceed .wait_until_api_failure_policy
62+ == WaitUntilApiFailurePolicy .PROCEED_ON_FAILURE
63+ )
64+
65+ # Test FAIL_WORKFLOW_ON_FAILURE
66+ options_fail = WorkflowStateOptions (
67+ proceed_to_execute_when_wait_until_retry_exhausted = WaitUntilApiFailurePolicy .FAIL_WORKFLOW_ON_FAILURE ,
68+ wait_until_api_retry_policy = retry_policy ,
69+ )
70+ result_fail = _to_idl_state_options (False , options_fail , {})
71+ assert (
72+ result_fail .wait_until_api_failure_policy
73+ == WaitUntilApiFailurePolicy .FAIL_WORKFLOW_ON_FAILURE
74+ )
75+
76+ # Test with None/unset value
77+ options = WorkflowStateOptions ()
78+ result = _to_idl_state_options (False , options , {})
79+ # By default, wait_until_api_failure_policy should not be set when proceed_to_execute_when_wait_until_retry_exhausted is None
80+ # The IWF service will use FAIL_WORKFLOW_ON_FAILURE by default
81+ from iwf .iwf_api .types import Unset
82+
83+ self .assertTrue (isinstance (result .wait_until_api_failure_policy , Unset ))
84+
85+ def test_proceed_on_failure (self ):
86+ wf_id = f"{ inspect .currentframe ().f_code .co_name } -{ time .time_ns ()} "
87+ self .client .start_workflow (
88+ StateOptionsWorkflow1 ,
89+ wf_id ,
90+ 10 ,
91+ "input" ,
92+ WorkflowOptions (workflow_id_reuse_policy = IDReusePolicy .DISALLOW_REUSE ),
93+ )
94+ output = self .client .wait_for_workflow_completion (wf_id )
95+
96+ assert output == "InitState1_execute_completed"
97+
98+ def test_fail_workflow_on_failure (self ):
99+ wf_id = f"{ inspect .currentframe ().f_code .co_name } -{ time .time_ns ()} "
100+ self .client .start_workflow (
101+ StateOptionsWorkflow2 ,
102+ wf_id ,
103+ 10 ,
104+ "input" ,
105+ WorkflowOptions (workflow_id_reuse_policy = IDReusePolicy .DISALLOW_REUSE ),
106+ )
107+
108+ with self .assertRaises (WorkflowFailed ):
109+ self .client .wait_for_workflow_completion (wf_id , str )
0 commit comments