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