1
1
import inspect
2
2
import time
3
3
import unittest
4
+ from time import sleep
4
5
5
6
from iwf .client import Client
6
- from iwf .command_request import CommandRequest , TimerCommand
7
+ from iwf .command_request import CommandRequest
7
8
from iwf .command_results import CommandResults
8
9
from iwf .communication import Communication
9
10
from iwf .iwf_api .models import SearchAttributeValueType
14
15
from iwf .tests .worker_server import registry
15
16
from iwf .workflow import ObjectWorkflow
16
17
from iwf .workflow_context import WorkflowContext
18
+ from iwf .workflow_options import WorkflowOptions
17
19
from iwf .workflow_state import T , WorkflowState
18
20
19
21
sa_keyword_key = "CustomKeywordField"
20
- sa_text_key = "CustomTextField"
21
22
sa_double_key = "CustomDoubleField"
22
23
sa_int_key = "CustomIntField"
23
24
sa_bool_key = "CustomBoolField"
24
25
sa_datetime_key = "CustomDatetimeField"
25
26
sa_keyword_array_key = "CustomKeywordArrayField"
26
27
27
28
sa_keyword : str = "keyword"
28
- sa_text : str = "text"
29
29
sa_double : float = 2.34
30
30
sa_int : int = 234
31
+ sa_bool : bool = False
31
32
sa_datetime : str = "2024-11-12T16:00:01.731455544-08:00"
32
33
sa_keyword_array : list [str ] = ["keyword-1" , "keyword-2" ]
33
34
34
35
final_sa_keyword : str = "final_keyword"
35
- final_sa_text = None
36
36
final_sa_int : int = 567
37
37
final_sa_bool : bool = False
38
38
final_sa_datetime : str = "2024-12-13T16:00:01.731455544-08:00"
@@ -47,14 +47,6 @@ def wait_until(
47
47
persistence : Persistence ,
48
48
communication : Communication ,
49
49
) -> CommandRequest :
50
- persistence .set_search_attribute_keyword (sa_keyword_key , sa_keyword )
51
- persistence .set_search_attribute_text (sa_text_key , sa_text )
52
- persistence .set_search_attribute_double (sa_double_key , sa_double )
53
- persistence .set_search_attribute_int64 (sa_int_key , sa_int )
54
- persistence .set_search_attribute_datetime (sa_datetime_key , sa_datetime )
55
- persistence .set_search_attribute_keyword_array (
56
- sa_keyword_array_key , sa_keyword_array
57
- )
58
50
return CommandRequest .empty ()
59
51
60
52
def execute (
@@ -65,6 +57,14 @@ def execute(
65
57
persistence : Persistence ,
66
58
communication : Communication ,
67
59
) -> StateDecision :
60
+ persistence .set_search_attribute_keyword (sa_keyword_key , sa_keyword )
61
+ persistence .set_search_attribute_double (sa_double_key , sa_double )
62
+ persistence .set_search_attribute_boolean (sa_bool_key , sa_bool )
63
+ persistence .set_search_attribute_keyword_array (
64
+ sa_keyword_array_key , sa_keyword_array
65
+ )
66
+ persistence .set_search_attribute_int64 (sa_int_key , sa_int )
67
+ persistence .set_search_attribute_datetime (sa_datetime_key , sa_datetime )
68
68
return StateDecision .single_next_state (SearchAttributeState2 )
69
69
70
70
@@ -76,9 +76,7 @@ def wait_until(
76
76
persistence : Persistence ,
77
77
communication : Communication ,
78
78
) -> CommandRequest :
79
- return CommandRequest .for_all_command_completed (
80
- TimerCommand .by_seconds (7 ),
81
- )
79
+ return CommandRequest .empty ()
82
80
83
81
def execute (
84
82
self ,
@@ -88,14 +86,15 @@ def execute(
88
86
persistence : Persistence ,
89
87
communication : Communication ,
90
88
) -> StateDecision :
89
+ # Delay updating search attributes to allow for the first assertion
90
+ sleep (1 )
91
91
persistence .set_search_attribute_keyword (sa_keyword_key , final_sa_keyword )
92
- persistence .set_search_attribute_text (sa_text_key , final_sa_text )
93
- persistence .set_search_attribute_int64 (sa_int_key , final_sa_int )
94
92
persistence .set_search_attribute_boolean (sa_bool_key , final_sa_bool )
95
- persistence .set_search_attribute_datetime (sa_datetime_key , final_sa_datetime )
96
93
persistence .set_search_attribute_keyword_array (
97
94
sa_keyword_array_key , final_sa_keyword_array
98
95
)
96
+ persistence .set_search_attribute_int64 (sa_int_key , final_sa_int )
97
+ persistence .set_search_attribute_datetime (sa_datetime_key , final_sa_datetime )
99
98
return StateDecision .graceful_complete_workflow ()
100
99
101
100
@@ -110,23 +109,20 @@ def get_persistence_schema(self) -> PersistenceSchema:
110
109
PersistenceField .search_attribute_def (
111
110
sa_keyword_key , SearchAttributeValueType .KEYWORD
112
111
),
113
- PersistenceField .search_attribute_def (
114
- sa_text_key , SearchAttributeValueType .TEXT
115
- ),
116
112
PersistenceField .search_attribute_def (
117
113
sa_double_key , SearchAttributeValueType .DOUBLE
118
114
),
119
115
PersistenceField .search_attribute_def (
120
- sa_int_key , SearchAttributeValueType .INT
116
+ sa_bool_key , SearchAttributeValueType .BOOL
121
117
),
122
118
PersistenceField .search_attribute_def (
123
- sa_bool_key , SearchAttributeValueType .BOOL
119
+ sa_keyword_array_key , SearchAttributeValueType .KEYWORD_ARRAY
124
120
),
125
121
PersistenceField .search_attribute_def (
126
- sa_datetime_key , SearchAttributeValueType .DATETIME
122
+ sa_int_key , SearchAttributeValueType .INT
127
123
),
128
124
PersistenceField .search_attribute_def (
129
- sa_keyword_array_key , SearchAttributeValueType .KEYWORD_ARRAY
125
+ sa_datetime_key , SearchAttributeValueType .DATETIME
130
126
),
131
127
)
132
128
@@ -141,22 +137,27 @@ def setUpClass(cls):
141
137
def test_persistence_search_attributes_workflow (self ):
142
138
wf_id = f"{ inspect .currentframe ().f_code .co_name } -{ time .time_ns ()} "
143
139
144
- self .client .start_workflow (PersistenceSearchAttributesWorkflow , wf_id , 100 )
140
+ wf_opts = WorkflowOptions ()
141
+ wf_opts .add_wait_for_completion_state_ids (SearchAttributeState1 )
142
+ self .client .start_workflow (
143
+ PersistenceSearchAttributesWorkflow , wf_id , 100 , None , wf_opts
144
+ )
145
145
146
- # TODO: Should be replaced with wait_for_state_execution_completed once implemented
147
- # https://github.com/indeedeng/iwf-python-sdk/issues/48
148
- time . sleep ( 5 )
146
+ self . client . wait_for_state_execution_completion_with_state_execution_id (
147
+ SearchAttributeState1 , wf_id
148
+ )
149
149
150
150
returned_search_attributes = self .client .get_all_search_attributes (
151
- PersistenceSearchAttributesWorkflow , wf_id
151
+ PersistenceSearchAttributesWorkflow ,
152
+ wf_id ,
152
153
)
153
154
154
155
expected_search_attributes = dict ()
155
156
expected_search_attributes [sa_keyword_key ] = sa_keyword
156
- expected_search_attributes [sa_text_key ] = sa_text
157
157
expected_search_attributes [sa_double_key ] = sa_double
158
- expected_search_attributes [sa_int_key ] = sa_int
158
+ expected_search_attributes [sa_bool_key ] = sa_bool
159
159
expected_search_attributes [sa_keyword_array_key ] = sa_keyword_array
160
+ expected_search_attributes [sa_int_key ] = sa_int
160
161
expected_search_attributes [sa_datetime_key ] = (
161
162
"2024-11-13T00:00:01.731455544Z" # This is a bug. The iwf-server always returns utc time. See https://github.com/indeedeng/iwf/issues/261
162
163
# "2024-11-12T18:00:01.731455544-06:00"
@@ -166,14 +167,8 @@ def test_persistence_search_attributes_workflow(self):
166
167
167
168
self .client .wait_for_workflow_completion (wf_id )
168
169
169
- final_returned_search_attributes = self .client .get_all_search_attributes (
170
- PersistenceSearchAttributesWorkflow ,
171
- wf_id ,
172
- )
173
-
174
170
final_expected_search_attributes = dict ()
175
171
final_expected_search_attributes [sa_keyword_key ] = final_sa_keyword
176
- final_expected_search_attributes [sa_text_key ] = ""
177
172
final_expected_search_attributes [sa_double_key ] = sa_double
178
173
final_expected_search_attributes [sa_int_key ] = final_sa_int
179
174
final_expected_search_attributes [sa_bool_key ] = final_sa_bool
@@ -183,4 +178,9 @@ def test_persistence_search_attributes_workflow(self):
183
178
# "2024-12-13T18:00:01.731455544-06:00"
184
179
)
185
180
181
+ final_returned_search_attributes = self .client .get_all_search_attributes (
182
+ PersistenceSearchAttributesWorkflow ,
183
+ wf_id ,
184
+ )
185
+
186
186
assert final_expected_search_attributes == final_returned_search_attributes
0 commit comments