11
2+ from datetime import datetime , timedelta , timezone
23from grpc ._channel import _InactiveRpcError
34import pytest
45from durabletask import client , task , worker
@@ -13,6 +14,10 @@ def empty_orchestrator(ctx: task.OrchestrationContext, _):
1314 return "Complete"
1415
1516
17+ def failing_orchestrator (ctx : task .OrchestrationContext , _ ):
18+ raise Exception ("Orchestration failed" )
19+
20+
1621def test_get_all_orchestration_states ():
1722 # Start a worker, which will connect to the sidecar in a background thread
1823 with worker .TaskHubGrpcWorker () as w :
@@ -26,3 +31,96 @@ def test_get_all_orchestration_states():
2631 with pytest .raises (_InactiveRpcError ) as exec_info :
2732 c .get_all_orchestration_states ()
2833 assert "unimplemented" in str (exec_info .value )
34+
35+
36+ def test_get_all_entities ():
37+ # Start a worker, which will connect to the sidecar in a background thread
38+ with worker .TaskHubGrpcWorker () as w :
39+ w .add_orchestrator (empty_orchestrator )
40+ w .start ()
41+
42+ c = client .TaskHubGrpcClient ()
43+ with pytest .raises (_InactiveRpcError ) as exec_info :
44+ c .get_all_entities ()
45+ assert "unimplemented" in str (exec_info .value )
46+
47+
48+ def test_clean_entity_storage ():
49+ # Start a worker, which will connect to the sidecar in a background thread
50+ with worker .TaskHubGrpcWorker () as w :
51+ w .add_orchestrator (empty_orchestrator )
52+ w .start ()
53+
54+ c = client .TaskHubGrpcClient ()
55+ with pytest .raises (_InactiveRpcError ) as exec_info :
56+ c .clean_entity_storage ()
57+ assert "unimplemented" in str (exec_info .value )
58+
59+
60+ def test_purge_orchestrations_by_status ():
61+ with worker .TaskHubGrpcWorker () as w :
62+ w .add_orchestrator (failing_orchestrator )
63+ w .start ()
64+
65+ c = client .TaskHubGrpcClient ()
66+
67+ # Schedule and let it fail
68+ failed_id = c .schedule_new_orchestration (failing_orchestrator )
69+ try :
70+ c .wait_for_orchestration_completion (failed_id , timeout = 30 )
71+ except client .OrchestrationFailedError :
72+ pass # Expected failure
73+
74+ # Verify it exists and is failed
75+ state_before = c .get_orchestration_state (failed_id )
76+ assert state_before is not None
77+ assert state_before .runtime_status == client .OrchestrationStatus .FAILED
78+
79+ # Purge failed orchestrations
80+ result = c .purge_orchestrations_by (
81+ runtime_status = [client .OrchestrationStatus .FAILED ],
82+ recursive = True
83+ )
84+
85+ # Verify purge result
86+ assert result .deleted_instance_count >= 1
87+
88+ # Verify the failed orchestration no longer exists
89+ state_after = c .get_orchestration_state (failed_id )
90+ assert state_after is None
91+
92+
93+ def test_purge_orchestrations_by_time_range ():
94+ with worker .TaskHubGrpcWorker () as w :
95+ w .add_orchestrator (empty_orchestrator )
96+ w .start ()
97+
98+ c = client .TaskHubGrpcClient ()
99+
100+ # Get current time
101+ before_creation = datetime .now (timezone .utc ) - timedelta (seconds = 5 )
102+
103+ # Schedule orchestration
104+ id = c .schedule_new_orchestration (empty_orchestrator , input = "ToPurgeByTime" )
105+ c .wait_for_orchestration_completion (id , timeout = 30 )
106+
107+ after_creation = datetime .now (timezone .utc ) + timedelta (seconds = 5 )
108+
109+ # Verify it exists
110+ state_before = c .get_orchestration_state (id )
111+ assert state_before is not None
112+
113+ # Purge by time range
114+ result = c .purge_orchestrations_by (
115+ created_time_from = before_creation ,
116+ created_time_to = after_creation ,
117+ runtime_status = [client .OrchestrationStatus .COMPLETED ],
118+ recursive = True
119+ )
120+
121+ # Verify purge result
122+ assert result .deleted_instance_count >= 1
123+
124+ # Verify it no longer exists
125+ state_after = c .get_orchestration_state (id )
126+ assert state_after is None
0 commit comments