-
Notifications
You must be signed in to change notification settings - Fork 203
Expand file tree
/
Copy pathtest_temporal_operation.py
More file actions
726 lines (622 loc) · 24.1 KB
/
Copy pathtest_temporal_operation.py
File metadata and controls
726 lines (622 loc) · 24.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
import asyncio
import uuid
from dataclasses import dataclass
import nexusrpc
import pytest
from nexusrpc import HandlerErrorType, Operation, service
from nexusrpc.handler import operation_handler, service_handler
from typing_extensions import override
import temporalio.exceptions
from temporalio import nexus, workflow
from temporalio.client import Client, WorkflowExecutionStatus, WorkflowFailureError
from temporalio.common import NexusOperationExecutionStatus, WorkflowIDConflictPolicy
from temporalio.nexus._token import OperationToken, OperationTokenType
from temporalio.testing import WorkflowEnvironment
from temporalio.worker import Worker
from tests.helpers import EventType, assert_event_subsequence, assert_eventually
from tests.helpers.nexus import make_nexus_endpoint_name
@dataclass
class Input:
value: str
task_queue: str
def test_temporal_operation_result_validates_single_result_kind() -> None:
assert nexus.TemporalOperationResult.sync(None).value is None
assert nexus.TemporalOperationResult.async_token("token").token == "token"
with pytest.raises(ValueError, match="exactly one of value or token"):
nexus.TemporalOperationResult()
with pytest.raises(ValueError, match="exactly one of value or token"):
nexus.TemporalOperationResult(value="value", token="token")
def test_temporal_operation_result_validates_token() -> None:
with pytest.raises(ValueError, match="non-empty string"):
nexus.TemporalOperationResult.async_token("")
with pytest.raises(ValueError, match="non-empty string"):
nexus.TemporalOperationResult(token="")
with pytest.raises(ValueError, match="non-empty string"):
nexus.TemporalOperationResult(token=123) # type: ignore
@workflow.defn
class EchoWorkflow:
@workflow.run
async def run(self, input: Input) -> str:
return input.value
@service
class TestService:
echo: Operation[Input, str]
blocking: Operation[None, None]
double_start: Operation[Input, None]
concurrent_start: Operation[Input, str]
retry_after_failed_start: Operation[Input, str]
sync_result: Operation[Input, str]
custom_cancel: Operation[str, None]
@service_handler(service=TestService)
class TestServiceHandler:
# tell Pytest this is not a test class
__test__ = False
def __init__(self) -> None:
self.started_custom_cancel_workflow = asyncio.Event()
@nexus.temporal_operation
async def echo(
self,
_ctx: nexus.TemporalStartOperationContext,
client: nexus.TemporalNexusClient,
input: Input,
) -> nexus.TemporalOperationResult[str]:
return await client.start_workflow(
EchoWorkflow.run, input, id=f"echo-{input.value}"
)
@nexus.temporal_operation
async def blocking(
self,
_ctx: nexus.TemporalStartOperationContext,
client: nexus.TemporalNexusClient,
_input: None,
) -> nexus.TemporalOperationResult[None]:
return await client.start_workflow(
BlockingWorkflow.run, id=f"blocking-{uuid.uuid4()}"
)
@nexus.temporal_operation
async def double_start(
self,
_ctx: nexus.TemporalStartOperationContext,
client: nexus.TemporalNexusClient,
input: Input,
) -> nexus.TemporalOperationResult[None]:
await client.start_workflow(
EchoWorkflow.run, input, id=f"double-start-{uuid.uuid4()}"
)
await client.start_workflow(
EchoWorkflow.run, input, id=f"double-start-{uuid.uuid4()}"
)
return nexus.TemporalOperationResult.sync(None)
@nexus.temporal_operation
async def concurrent_start(
self,
_ctx: nexus.TemporalStartOperationContext,
client: nexus.TemporalNexusClient,
input: Input,
) -> nexus.TemporalOperationResult[str]:
results = await asyncio.gather(
client.start_workflow(
EchoWorkflow.run,
input,
id=f"concurrent-start-1-{uuid.uuid4()}",
),
client.start_workflow(
EchoWorkflow.run,
input,
id=f"concurrent-start-2-{uuid.uuid4()}",
),
return_exceptions=True,
)
async_results: list[nexus.TemporalOperationResult[str]] = []
handler_errors: list[nexusrpc.HandlerError] = []
for result in results:
if isinstance(result, nexus.TemporalOperationResult):
async_results.append(result)
elif isinstance(result, nexusrpc.HandlerError):
handler_errors.append(result)
elif isinstance(result, BaseException):
raise result
else:
raise RuntimeError(f"Unexpected concurrent start result: {result}")
if (
len(async_results) == 1
and len(handler_errors) == 1
and handler_errors[0].type == HandlerErrorType.BAD_REQUEST
):
return async_results[0]
raise RuntimeError(
"Expected one async workflow start and one BAD_REQUEST HandlerError, "
f"got {len(async_results)} starts and {len(handler_errors)} handler errors"
)
@nexus.temporal_operation
async def retry_after_failed_start(
self,
_ctx: nexus.TemporalStartOperationContext,
client: nexus.TemporalNexusClient,
input: Input,
) -> nexus.TemporalOperationResult[str]:
try:
await client.start_workflow(
BlockingWorkflow.run,
id=input.value,
id_conflict_policy=WorkflowIDConflictPolicy.FAIL,
)
except temporalio.exceptions.WorkflowAlreadyStartedError:
return await client.start_workflow(
EchoWorkflow.run,
input,
id=f"retry-after-failed-start-{uuid.uuid4()}",
)
raise RuntimeError("Expected first workflow start to fail")
@nexus.temporal_operation
async def sync_result(
self,
_ctx: nexus.TemporalStartOperationContext,
_client: nexus.TemporalNexusClient,
input: Input,
) -> nexus.TemporalOperationResult[str]:
return nexus.TemporalOperationResult.sync(input.value)
@operation_handler
def custom_cancel(self) -> nexus.TemporalOperationHandler[str, None]:
event = self.started_custom_cancel_workflow
class CustomCancelNexusOpHandler(nexus.TemporalOperationHandler[str, None]):
@override
async def start_operation(
self,
ctx: nexus.TemporalStartOperationContext,
client: nexus.TemporalNexusClient,
input: str,
) -> nexus.TemporalOperationResult[None]:
result = await client.start_workflow(BlockingWorkflow.run, id=input)
event.set()
return result
@override
async def cancel_workflow_run(
self,
ctx: nexus.TemporalCancelOperationContext,
options: nexus.CancelWorkflowRunOptions,
):
# get a handle to the workflow
handle = nexus.client().get_workflow_handle(options.workflow_id)
# cancel the workflow
await handle.cancel()
return CustomCancelNexusOpHandler()
@workflow.defn
class EchoWorkflowCaller:
@workflow.run
async def run(self, input: Input) -> str:
client = workflow.create_nexus_client(
service=TestService, endpoint=make_nexus_endpoint_name(input.task_queue)
)
return await client.execute_operation(TestService.echo, input)
async def test_temporal_operation_start_workflow(
client: Client, env: WorkflowEnvironment
):
task_queue = str(uuid.uuid4())
endpoint_name = make_nexus_endpoint_name(task_queue)
await env.create_nexus_endpoint(endpoint_name, task_queue)
async with Worker(
env.client,
task_queue=task_queue,
nexus_service_handlers=[TestServiceHandler()],
workflows=[EchoWorkflow, EchoWorkflowCaller],
):
wf_handle = await client.start_workflow(
EchoWorkflowCaller.run,
Input(value="test", task_queue=task_queue),
task_queue=task_queue,
id=str(uuid.uuid4()),
)
result = await wf_handle.result()
assert result == "test"
await assert_event_subsequence(
wf_handle,
[
EventType.EVENT_TYPE_NEXUS_OPERATION_SCHEDULED,
EventType.EVENT_TYPE_NEXUS_OPERATION_STARTED,
EventType.EVENT_TYPE_NEXUS_OPERATION_COMPLETED,
],
)
@workflow.defn
class BlockingWorkflow:
def __init__(self) -> None:
self.done: bool = False
@workflow.run
async def run(self) -> None:
await workflow.wait_condition(lambda: self.done)
@workflow.update
async def unblock(self):
self.done = True
@workflow.defn
class CancelBlockingWorkflowCaller:
op_started = False
@workflow.run
async def run(self, input: Input) -> None:
client = workflow.create_nexus_client(
service=TestService, endpoint=make_nexus_endpoint_name(input.task_queue)
)
op_handle = await client.start_operation(TestService.blocking, None)
self.op_started = True
return await op_handle
@workflow.update
async def wait_operation_started(self):
await workflow.wait_condition(lambda: self.op_started)
async def test_temporal_operation_cancel_workflow(
client: Client, env: WorkflowEnvironment
):
task_queue = str(uuid.uuid4())
endpoint_name = make_nexus_endpoint_name(task_queue)
await env.create_nexus_endpoint(endpoint_name, task_queue)
async with Worker(
env.client,
task_queue=task_queue,
nexus_service_handlers=[TestServiceHandler()],
workflows=[BlockingWorkflow, CancelBlockingWorkflowCaller],
):
wf_handle = await client.start_workflow(
CancelBlockingWorkflowCaller.run,
Input(value="test", task_queue=task_queue),
task_queue=task_queue,
id=f"blocking-{uuid.uuid4()}",
)
await wf_handle.execute_update(
CancelBlockingWorkflowCaller.wait_operation_started
)
await wf_handle.cancel()
await assert_event_subsequence(
wf_handle,
[
EventType.EVENT_TYPE_NEXUS_OPERATION_CANCEL_REQUESTED,
EventType.EVENT_TYPE_NEXUS_OPERATION_CANCEL_REQUEST_COMPLETED,
EventType.EVENT_TYPE_NEXUS_OPERATION_CANCELED,
],
)
async def test_customized_temporal_operation_cancel_workflow(
client: Client, env: WorkflowEnvironment
):
if env.supports_time_skipping:
pytest.skip(
"Standalone Nexus Operation tests don't work with time-skipping server"
)
task_queue = str(uuid.uuid4())
endpoint_name = make_nexus_endpoint_name(task_queue)
await env.create_nexus_endpoint(endpoint_name, task_queue)
service_handler = TestServiceHandler()
async with Worker(
env.client,
task_queue=task_queue,
nexus_service_handlers=[service_handler],
workflows=[BlockingWorkflow, CancelBlockingWorkflowCaller],
):
nexus_client = client.create_nexus_client(TestService, endpoint_name)
wf_id = f"custom-cancel-{uuid.uuid4()}"
op_handle = await nexus_client.start_operation(
TestService.custom_cancel, wf_id, id=str(uuid.uuid4())
)
await service_handler.started_custom_cancel_workflow.wait()
await op_handle.cancel()
async def check_cancelled():
wf_handle = client.get_workflow_handle(wf_id)
wf_desc = await wf_handle.describe()
assert wf_desc.status is WorkflowExecutionStatus.CANCELED
op_desc = await op_handle.describe()
assert op_desc.status is NexusOperationExecutionStatus.CANCELED
await assert_eventually(check_cancelled)
@workflow.defn
class DoubleStartWorkflowCaller:
@workflow.run
async def run(self, input: Input) -> None:
client = workflow.create_nexus_client(
service=TestService, endpoint=make_nexus_endpoint_name(input.task_queue)
)
op_handle = await client.start_operation(TestService.double_start, input)
return await op_handle
@workflow.defn
class ConcurrentStartWorkflowCaller:
@workflow.run
async def run(self, input: Input) -> str:
client = workflow.create_nexus_client(
service=TestService, endpoint=make_nexus_endpoint_name(input.task_queue)
)
return await client.execute_operation(TestService.concurrent_start, input)
@workflow.defn
class FailedStartRollbackWorkflowCaller:
@workflow.run
async def run(self, input: Input) -> str:
client = workflow.create_nexus_client(
service=TestService, endpoint=make_nexus_endpoint_name(input.task_queue)
)
return await client.execute_operation(
TestService.retry_after_failed_start,
input,
)
async def test_temporal_operation_double_start_raises_handler_err(
client: Client, env: WorkflowEnvironment
):
task_queue = str(uuid.uuid4())
endpoint_name = make_nexus_endpoint_name(task_queue)
await env.create_nexus_endpoint(endpoint_name, task_queue)
async with Worker(
env.client,
task_queue=task_queue,
nexus_service_handlers=[TestServiceHandler()],
workflows=[EchoWorkflow, DoubleStartWorkflowCaller],
):
with pytest.raises(WorkflowFailureError) as err:
await client.execute_workflow(
DoubleStartWorkflowCaller.run,
Input(value="test", task_queue=task_queue),
task_queue=task_queue,
id=f"double-start-{uuid.uuid4()}",
)
assert isinstance(err.value.cause, temporalio.exceptions.NexusOperationError)
assert isinstance(err.value.cause.cause, nexusrpc.HandlerError)
assert err.value.cause.cause.type == HandlerErrorType.BAD_REQUEST
assert (
"Only one async operation can be started per operation handler invocation"
in err.value.cause.cause.message
)
async def test_temporal_operation_concurrent_start_raises_handler_err(
client: Client, env: WorkflowEnvironment
):
task_queue = str(uuid.uuid4())
endpoint_name = make_nexus_endpoint_name(task_queue)
await env.create_nexus_endpoint(endpoint_name, task_queue)
async with Worker(
env.client,
task_queue=task_queue,
nexus_service_handlers=[TestServiceHandler()],
workflows=[EchoWorkflow, ConcurrentStartWorkflowCaller],
):
result = await client.execute_workflow(
ConcurrentStartWorkflowCaller.run,
Input(value="test", task_queue=task_queue),
task_queue=task_queue,
id=f"concurrent-start-{uuid.uuid4()}",
)
assert result == "test"
async def test_temporal_operation_failed_start_allows_retry(
client: Client, env: WorkflowEnvironment
):
task_queue = str(uuid.uuid4())
endpoint_name = make_nexus_endpoint_name(task_queue)
conflict_id = f"failed-start-rollback-{uuid.uuid4()}"
await env.create_nexus_endpoint(endpoint_name, task_queue)
async with Worker(
env.client,
task_queue=task_queue,
nexus_service_handlers=[TestServiceHandler()],
workflows=[
BlockingWorkflow,
EchoWorkflow,
FailedStartRollbackWorkflowCaller,
],
):
conflict_handle = await client.start_workflow(
BlockingWorkflow.run,
id=conflict_id,
task_queue=task_queue,
)
try:
result = await client.execute_workflow(
FailedStartRollbackWorkflowCaller.run,
Input(value=conflict_id, task_queue=task_queue),
task_queue=task_queue,
id=f"failed-start-rollback-caller-{uuid.uuid4()}",
)
assert result == conflict_id
finally:
await conflict_handle.cancel()
@workflow.defn
class SyncResultCaller:
@workflow.run
async def run(self, input: Input) -> str:
client = workflow.create_nexus_client(
service=TestService, endpoint=make_nexus_endpoint_name(input.task_queue)
)
return await client.execute_operation(TestService.sync_result, input)
async def test_temporal_operation_sync_result(client: Client, env: WorkflowEnvironment):
task_queue = str(uuid.uuid4())
endpoint_name = make_nexus_endpoint_name(task_queue)
await env.create_nexus_endpoint(endpoint_name, task_queue)
async with Worker(
env.client,
task_queue=task_queue,
nexus_service_handlers=[TestServiceHandler()],
workflows=[SyncResultCaller],
):
wf_handle = await client.start_workflow(
SyncResultCaller.run,
Input(value="test", task_queue=task_queue),
task_queue=task_queue,
id=str(uuid.uuid4()),
)
result = await wf_handle.result()
assert result == "test"
# Sync results do not produce a NEXUS_OPERATION_STARTED event,
await assert_event_subsequence(
wf_handle,
[
EventType.EVENT_TYPE_NEXUS_OPERATION_SCHEDULED,
EventType.EVENT_TYPE_NEXUS_OPERATION_COMPLETED,
],
)
@dataclass
class TemporalOperationOverloadTestValue:
value: int
@workflow.defn
class TemporalOperationOverloadTestWorkflow:
@workflow.run
async def run(
self, input: TemporalOperationOverloadTestValue
) -> TemporalOperationOverloadTestValue:
return TemporalOperationOverloadTestValue(value=input.value * 2)
@workflow.defn
class TemporalOperationOverloadTestWorkflowNoParam:
@workflow.run
async def run(self) -> TemporalOperationOverloadTestValue:
return TemporalOperationOverloadTestValue(value=0)
@service_handler
class TemporalOperationOverloadTestServiceHandler:
@nexus.temporal_operation
async def no_param(
self,
_ctx: nexus.TemporalStartOperationContext,
client: nexus.TemporalNexusClient,
_input: TemporalOperationOverloadTestValue,
) -> nexus.TemporalOperationResult[TemporalOperationOverloadTestValue]:
return await client.start_workflow(
TemporalOperationOverloadTestWorkflowNoParam.run,
id=str(uuid.uuid4()),
)
@nexus.temporal_operation
async def single_param(
self,
_ctx: nexus.TemporalStartOperationContext,
client: nexus.TemporalNexusClient,
input: TemporalOperationOverloadTestValue,
) -> nexus.TemporalOperationResult[TemporalOperationOverloadTestValue]:
return await client.start_workflow(
TemporalOperationOverloadTestWorkflow.run,
input,
id=str(uuid.uuid4()),
)
@nexus.temporal_operation
async def multi_param(
self,
_ctx: nexus.TemporalStartOperationContext,
client: nexus.TemporalNexusClient,
input: TemporalOperationOverloadTestValue,
) -> nexus.TemporalOperationResult[TemporalOperationOverloadTestValue]:
return await client.start_workflow(
TemporalOperationOverloadTestWorkflow.run,
args=[input],
id=str(uuid.uuid4()),
)
@nexus.temporal_operation
async def by_name(
self,
_ctx: nexus.TemporalStartOperationContext,
client: nexus.TemporalNexusClient,
input: TemporalOperationOverloadTestValue,
) -> nexus.TemporalOperationResult[TemporalOperationOverloadTestValue]:
return await client.start_workflow(
"TemporalOperationOverloadTestWorkflow",
input,
id=str(uuid.uuid4()),
result_type=TemporalOperationOverloadTestValue,
)
@nexus.temporal_operation
async def by_name_multi_param(
self,
_ctx: nexus.TemporalStartOperationContext,
client: nexus.TemporalNexusClient,
input: TemporalOperationOverloadTestValue,
) -> nexus.TemporalOperationResult[TemporalOperationOverloadTestValue]:
return await client.start_workflow(
"TemporalOperationOverloadTestWorkflow",
args=[input],
id=str(uuid.uuid4()),
result_type=TemporalOperationOverloadTestValue,
)
@workflow.defn
class TemporalOperationOverloadTestCallerWorkflow:
@workflow.run
async def run(
self, op: str, input: TemporalOperationOverloadTestValue
) -> TemporalOperationOverloadTestValue:
client = workflow.create_nexus_client(
service=TemporalOperationOverloadTestServiceHandler,
endpoint=make_nexus_endpoint_name(workflow.info().task_queue),
)
if op == "no_param":
return await client.execute_operation(
TemporalOperationOverloadTestServiceHandler.no_param, input
)
elif op == "single_param":
return await client.execute_operation(
TemporalOperationOverloadTestServiceHandler.single_param, input
)
elif op == "multi_param":
return await client.execute_operation(
TemporalOperationOverloadTestServiceHandler.multi_param, input
)
elif op == "by_name":
return await client.execute_operation(
TemporalOperationOverloadTestServiceHandler.by_name, input
)
elif op == "by_name_multi_param":
return await client.execute_operation(
TemporalOperationOverloadTestServiceHandler.by_name_multi_param, input
)
else:
raise ValueError(f"Unknown op: {op}")
@pytest.mark.parametrize(
"op",
[
"no_param",
"single_param",
"multi_param",
"by_name",
"by_name_multi_param",
],
)
async def test_temporal_operation_overloads(
client: Client, env: WorkflowEnvironment, op: str
):
task_queue = str(uuid.uuid4())
endpoint_name = make_nexus_endpoint_name(task_queue)
await env.create_nexus_endpoint(endpoint_name, task_queue)
async with Worker(
client,
task_queue=task_queue,
workflows=[
TemporalOperationOverloadTestCallerWorkflow,
TemporalOperationOverloadTestWorkflow,
TemporalOperationOverloadTestWorkflowNoParam,
],
nexus_service_handlers=[TemporalOperationOverloadTestServiceHandler()],
):
result = await client.execute_workflow(
TemporalOperationOverloadTestCallerWorkflow.run,
args=[op, TemporalOperationOverloadTestValue(value=2)],
id=str(uuid.uuid4()),
task_queue=task_queue,
)
assert result == (
TemporalOperationOverloadTestValue(value=0)
if op == "no_param"
else TemporalOperationOverloadTestValue(value=4)
)
async def test_temporal_operation_includes_token_in_callback(
client: Client, env: WorkflowEnvironment
):
task_queue = str(uuid.uuid4())
endpoint_name = make_nexus_endpoint_name(task_queue)
await env.create_nexus_endpoint(endpoint_name, task_queue)
async with Worker(
env.client,
task_queue=task_queue,
nexus_service_handlers=[TestServiceHandler()],
workflows=[EchoWorkflow, EchoWorkflowCaller],
):
input_value = f"test-{uuid.uuid4()}"
wf_handle = await client.start_workflow(
EchoWorkflowCaller.run,
Input(value=input_value, task_queue=task_queue),
task_queue=task_queue,
id=str(uuid.uuid4()),
)
result = await wf_handle.result()
assert result == input_value
target_handle = client.get_workflow_handle(f"echo-{input_value}")
desc = await target_handle.describe()
token = desc.raw_description.callbacks[0].callback.nexus.header[
"nexus-operation-token"
]
expected_token = OperationToken(
type=OperationTokenType.WORKFLOW,
namespace=client.namespace,
workflow_id=target_handle.id,
).encode()
assert token == expected_token