22# Licensed under the MIT License.
33
44import json
5- import threading
6- import time
75import os
6+ import threading
87from datetime import timedelta
98
109import pytest
2120taskhub_name = os .getenv ("TASKHUB" , "default" )
2221endpoint = os .getenv ("ENDPOINT" , "http://localhost:8080" )
2322
23+
2424def test_empty_orchestration ():
2525
2626 invoked = False
@@ -31,12 +31,12 @@ def empty_orchestrator(ctx: task.OrchestrationContext, _):
3131
3232 # Start a worker, which will connect to the sidecar in a background thread
3333 with DurableTaskSchedulerWorker (host_address = endpoint , secure_channel = True ,
34- taskhub = taskhub_name , token_credential = None ) as w :
34+ taskhub = taskhub_name , token_credential = None ) as w :
3535 w .add_orchestrator (empty_orchestrator )
3636 w .start ()
3737
3838 c = DurableTaskSchedulerClient (host_address = endpoint , secure_channel = True ,
39- taskhub = taskhub_name , token_credential = None )
39+ taskhub = taskhub_name , token_credential = None )
4040 id = c .schedule_new_orchestration (empty_orchestrator )
4141 state = c .wait_for_orchestration_completion (id , timeout = 30 )
4242
@@ -66,13 +66,13 @@ def sequence(ctx: task.OrchestrationContext, start_val: int):
6666
6767 # Start a worker, which will connect to the sidecar in a background thread
6868 with DurableTaskSchedulerWorker (host_address = endpoint , secure_channel = True ,
69- taskhub = taskhub_name , token_credential = None ) as w :
69+ taskhub = taskhub_name , token_credential = None ) as w :
7070 w .add_orchestrator (sequence )
7171 w .add_activity (plus_one )
7272 w .start ()
7373
7474 task_hub_client = DurableTaskSchedulerClient (host_address = endpoint , secure_channel = True ,
75- taskhub = taskhub_name , token_credential = None )
75+ taskhub = taskhub_name , token_credential = None )
7676 id = task_hub_client .schedule_new_orchestration (sequence , input = 1 )
7777 state = task_hub_client .wait_for_orchestration_completion (
7878 id , timeout = 30 )
@@ -113,14 +113,14 @@ def orchestrator(ctx: task.OrchestrationContext, input: int):
113113
114114 # Start a worker, which will connect to the sidecar in a background thread
115115 with DurableTaskSchedulerWorker (host_address = endpoint , secure_channel = True ,
116- taskhub = taskhub_name , token_credential = None ) as w :
116+ taskhub = taskhub_name , token_credential = None ) as w :
117117 w .add_orchestrator (orchestrator )
118118 w .add_activity (throw )
119119 w .add_activity (increment_counter )
120120 w .start ()
121121
122122 task_hub_client = DurableTaskSchedulerClient (host_address = endpoint , secure_channel = True ,
123- taskhub = taskhub_name , token_credential = None )
123+ taskhub = taskhub_name , token_credential = None )
124124 id = task_hub_client .schedule_new_orchestration (orchestrator , input = 1 )
125125 state = task_hub_client .wait_for_orchestration_completion (id , timeout = 30 )
126126
@@ -158,14 +158,14 @@ def parent_orchestrator(ctx: task.OrchestrationContext, count: int):
158158
159159 # Start a worker, which will connect to the sidecar in a background thread
160160 with DurableTaskSchedulerWorker (host_address = endpoint , secure_channel = True ,
161- taskhub = taskhub_name , token_credential = None ) as w :
161+ taskhub = taskhub_name , token_credential = None ) as w :
162162 w .add_activity (increment )
163163 w .add_orchestrator (orchestrator_child )
164164 w .add_orchestrator (parent_orchestrator )
165165 w .start ()
166166
167167 task_hub_client = DurableTaskSchedulerClient (host_address = endpoint , secure_channel = True ,
168- taskhub = taskhub_name , token_credential = None )
168+ taskhub = taskhub_name , token_credential = None )
169169 id = task_hub_client .schedule_new_orchestration (parent_orchestrator , input = 10 )
170170 state = task_hub_client .wait_for_orchestration_completion (id , timeout = 30 )
171171
@@ -184,13 +184,13 @@ def orchestrator(ctx: task.OrchestrationContext, _):
184184
185185 # Start a worker, which will connect to the sidecar in a background thread
186186 with DurableTaskSchedulerWorker (host_address = endpoint , secure_channel = True ,
187- taskhub = taskhub_name , token_credential = None ) as w :
187+ taskhub = taskhub_name , token_credential = None ) as w :
188188 w .add_orchestrator (orchestrator )
189189 w .start ()
190190
191191 # Start the orchestration and immediately raise events to it.
192192 task_hub_client = DurableTaskSchedulerClient (host_address = endpoint , secure_channel = True ,
193- taskhub = taskhub_name , token_credential = None )
193+ taskhub = taskhub_name , token_credential = None )
194194 id = task_hub_client .schedule_new_orchestration (orchestrator )
195195 task_hub_client .raise_orchestration_event (id , 'A' , data = 'a' )
196196 task_hub_client .raise_orchestration_event (id , 'B' , data = 'b' )
@@ -285,12 +285,12 @@ def orchestrator(ctx: task.OrchestrationContext, _):
285285
286286 # Start a worker, which will connect to the sidecar in a background thread
287287 with DurableTaskSchedulerWorker (host_address = endpoint , secure_channel = True ,
288- taskhub = taskhub_name , token_credential = None ) as w :
288+ taskhub = taskhub_name , token_credential = None ) as w :
289289 w .add_orchestrator (orchestrator )
290290 w .start ()
291291
292292 task_hub_client = DurableTaskSchedulerClient (host_address = endpoint , secure_channel = True ,
293- taskhub = taskhub_name , token_credential = None )
293+ taskhub = taskhub_name , token_credential = None )
294294 id = task_hub_client .schedule_new_orchestration (orchestrator )
295295 state = task_hub_client .wait_for_orchestration_start (id , timeout = 30 )
296296 assert state is not None
@@ -302,23 +302,25 @@ def orchestrator(ctx: task.OrchestrationContext, _):
302302 assert state .runtime_status == client .OrchestrationStatus .TERMINATED
303303 assert state .serialized_output == json .dumps ("some reason for termination" )
304304
305+
305306def test_terminate_recursive ():
306307 def root (ctx : task .OrchestrationContext , _ ):
307308 result = yield ctx .call_sub_orchestrator (child )
308309 return result
310+
309311 def child (ctx : task .OrchestrationContext , _ ):
310312 result = yield ctx .wait_for_external_event ("my_event" )
311313 return result
312314
313315 # Start a worker, which will connect to the sidecar in a background thread
314316 with DurableTaskSchedulerWorker (host_address = endpoint , secure_channel = True ,
315- taskhub = taskhub_name , token_credential = None ) as w :
317+ taskhub = taskhub_name , token_credential = None ) as w :
316318 w .add_orchestrator (root )
317319 w .add_orchestrator (child )
318320 w .start ()
319321
320322 task_hub_client = DurableTaskSchedulerClient (host_address = endpoint , secure_channel = True ,
321- taskhub = taskhub_name , token_credential = None )
323+ taskhub = taskhub_name , token_credential = None )
322324 id = task_hub_client .schedule_new_orchestration (root )
323325 state = task_hub_client .wait_for_orchestration_start (id , timeout = 30 )
324326 assert state is not None
@@ -331,7 +333,7 @@ def child(ctx: task.OrchestrationContext, _):
331333 assert state .runtime_status == client .OrchestrationStatus .TERMINATED
332334
333335 # Verify that child orchestration is also terminated
334- c = task_hub_client .wait_for_orchestration_completion (id , timeout = 30 )
336+ task_hub_client .wait_for_orchestration_completion (id , timeout = 30 )
335337 assert state is not None
336338 assert state .runtime_status == client .OrchestrationStatus .TERMINATED
337339
@@ -417,14 +419,14 @@ def throw_activity_with_retry(ctx: task.ActivityContext, _):
417419 raise RuntimeError ("Kah-BOOOOM!!!" )
418420
419421 with DurableTaskSchedulerWorker (host_address = endpoint , secure_channel = True ,
420- taskhub = taskhub_name , token_credential = None ) as w :
422+ taskhub = taskhub_name , token_credential = None ) as w :
421423 w .add_orchestrator (parent_orchestrator_with_retry )
422424 w .add_orchestrator (child_orchestrator_with_retry )
423425 w .add_activity (throw_activity_with_retry )
424426 w .start ()
425427
426428 task_hub_client = DurableTaskSchedulerClient (host_address = endpoint , secure_channel = True ,
427- taskhub = taskhub_name , token_credential = None )
429+ taskhub = taskhub_name , token_credential = None )
428430 id = task_hub_client .schedule_new_orchestration (parent_orchestrator_with_retry )
429431 state = task_hub_client .wait_for_orchestration_completion (id , timeout = 30 )
430432 assert state is not None
@@ -460,13 +462,13 @@ def throw_activity(ctx: task.ActivityContext, _):
460462 raise RuntimeError ("Kah-BOOOOM!!!" )
461463
462464 with DurableTaskSchedulerWorker (host_address = endpoint , secure_channel = True ,
463- taskhub = taskhub_name , token_credential = None ) as w :
465+ taskhub = taskhub_name , token_credential = None ) as w :
464466 w .add_orchestrator (mock_orchestrator )
465467 w .add_activity (throw_activity )
466468 w .start ()
467469
468470 task_hub_client = DurableTaskSchedulerClient (host_address = endpoint , secure_channel = True ,
469- taskhub = taskhub_name , token_credential = None )
471+ taskhub = taskhub_name , token_credential = None )
470472 id = task_hub_client .schedule_new_orchestration (mock_orchestrator )
471473 state = task_hub_client .wait_for_orchestration_completion (id , timeout = 30 )
472474 assert state is not None
@@ -477,19 +479,20 @@ def throw_activity(ctx: task.ActivityContext, _):
477479 assert state .failure_details .stack_trace is not None
478480 assert throw_activity_counter == 4
479481
482+
480483def test_custom_status ():
481484
482485 def empty_orchestrator (ctx : task .OrchestrationContext , _ ):
483486 ctx .set_custom_status ("foobaz" )
484487
485488 # Start a worker, which will connect to the sidecar in a background thread
486489 with DurableTaskSchedulerWorker (host_address = endpoint , secure_channel = True ,
487- taskhub = taskhub_name , token_credential = None ) as w :
490+ taskhub = taskhub_name , token_credential = None ) as w :
488491 w .add_orchestrator (empty_orchestrator )
489492 w .start ()
490493
491494 c = DurableTaskSchedulerClient (host_address = endpoint , secure_channel = True ,
492- taskhub = taskhub_name , token_credential = None )
495+ taskhub = taskhub_name , token_credential = None )
493496 id = c .schedule_new_orchestration (empty_orchestrator )
494497 state = c .wait_for_orchestration_completion (id , timeout = 30 )
495498
0 commit comments