|
12 | 12 | Client,
|
13 | 13 | Interceptor,
|
14 | 14 | OutboundInterceptor,
|
| 15 | + RPCError, |
15 | 16 | StartWorkflowInput,
|
16 | 17 | WorkflowFailureError,
|
17 | 18 | WorkflowHandle,
|
18 | 19 | )
|
19 |
| -from temporalio.common import RetryPolicy |
| 20 | +from temporalio.common import ( |
| 21 | + RetryPolicy, |
| 22 | + SearchAttributeKey, |
| 23 | + SearchAttributePair, |
| 24 | + TypedSearchAttributes, |
| 25 | +) |
20 | 26 | from temporalio.exceptions import (
|
21 | 27 | ActivityError,
|
22 | 28 | ApplicationError,
|
@@ -245,6 +251,70 @@ def assert_proper_error(err: Optional[BaseException]) -> None:
|
245 | 251 | assert_proper_error(err.value.cause)
|
246 | 252 |
|
247 | 253 |
|
| 254 | +async def test_search_attributes_on_dev_server( |
| 255 | + client: Client, env: WorkflowEnvironment |
| 256 | +): |
| 257 | + if env.supports_time_skipping: |
| 258 | + pytest.skip("Only testing for local dev server") |
| 259 | + |
| 260 | + # Search attributes |
| 261 | + sa_prefix = f"{uuid.uuid4()}_" |
| 262 | + text_attr = SearchAttributeKey.for_text(f"{sa_prefix}text") |
| 263 | + keyword_attr = SearchAttributeKey.for_keyword(f"{sa_prefix}keyword") |
| 264 | + keyword_list_attr = SearchAttributeKey.for_keyword_list(f"{sa_prefix}keyword_list") |
| 265 | + int_attr = SearchAttributeKey.for_int(f"{sa_prefix}int") |
| 266 | + float_attr = SearchAttributeKey.for_float(f"{sa_prefix}double") |
| 267 | + bool_attr = SearchAttributeKey.for_bool(f"{sa_prefix}bool") |
| 268 | + datetime_attr = SearchAttributeKey.for_datetime(f"{sa_prefix}datetime") |
| 269 | + attrs = TypedSearchAttributes( |
| 270 | + [ |
| 271 | + SearchAttributePair(text_attr, "text1"), |
| 272 | + SearchAttributePair(keyword_attr, "keyword1"), |
| 273 | + SearchAttributePair( |
| 274 | + keyword_list_attr, |
| 275 | + ["keywordlist1", "keywordlist2"], |
| 276 | + ), |
| 277 | + SearchAttributePair(int_attr, 123), |
| 278 | + SearchAttributePair(float_attr, 456.78), |
| 279 | + SearchAttributePair(bool_attr, True), |
| 280 | + SearchAttributePair( |
| 281 | + datetime_attr, datetime(2001, 2, 3, 4, 5, 6, tzinfo=timezone.utc) |
| 282 | + ), |
| 283 | + ] |
| 284 | + ) |
| 285 | + |
| 286 | + # Confirm that we can't start a workflow on existing environment |
| 287 | + with pytest.raises(RPCError) as err: |
| 288 | + await client.start_workflow( |
| 289 | + "some-workflow", |
| 290 | + id=f"wf-{uuid.uuid4()}", |
| 291 | + task_queue=f"tq-{uuid.uuid4()}", |
| 292 | + search_attributes=attrs, |
| 293 | + ) |
| 294 | + assert "no mapping defined" in str(err.value) |
| 295 | + |
| 296 | + # But we can in a new environment with the attrs set |
| 297 | + async with await WorkflowEnvironment.start_local( |
| 298 | + search_attributes=[ |
| 299 | + text_attr, |
| 300 | + keyword_attr, |
| 301 | + keyword_list_attr, |
| 302 | + int_attr, |
| 303 | + float_attr, |
| 304 | + bool_attr, |
| 305 | + datetime_attr, |
| 306 | + ] |
| 307 | + ) as env: |
| 308 | + handle = await env.client.start_workflow( |
| 309 | + "some-workflow", |
| 310 | + id=f"wf-{uuid.uuid4()}", |
| 311 | + task_queue=f"tq-{uuid.uuid4()}", |
| 312 | + search_attributes=attrs, |
| 313 | + ) |
| 314 | + desc = await handle.describe() |
| 315 | + assert attrs == desc.typed_search_attributes |
| 316 | + |
| 317 | + |
248 | 318 | def assert_timestamp_from_now(
|
249 | 319 | ts: Union[datetime, float], expected_from_now: float, max_delta: float = 30
|
250 | 320 | ) -> None:
|
|
0 commit comments