Skip to content

Commit e320920

Browse files
committed
Real fix
1 parent 840b2f1 commit e320920

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

durabletask/testing/in_memory_backend.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,14 @@ def RaiseEvent(self, request: pb.RaiseEventRequest, context):
309309
)
310310
instance.pending_events.append(event)
311311
instance.last_updated_at = datetime.now(timezone.utc)
312-
self._enqueue_orchestration(instance.instance_id)
312+
313+
# Don't dispatch work for suspended or terminal orchestrations;
314+
# suspended events will be delivered when the orchestration is
315+
# resumed, and terminal orchestrations can't process new events.
316+
not_terminal = not self._is_terminal_status(instance.status)
317+
not_suspended = instance.status != pb.ORCHESTRATION_STATUS_SUSPENDED
318+
if not_terminal and not_suspended:
319+
self._enqueue_orchestration(instance.instance_id)
313320

314321
self._logger.info(f"Raised event '{request.name}' for instance '{request.instanceId}'")
315322
return pb.RaiseEventResponse()

tests/durabletask/test_orchestration_async_e2e.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,10 @@ def orchestrator(ctx: task.OrchestrationContext, _):
128128
assert state is not None
129129
assert state.runtime_status == client.OrchestrationStatus.SUSPENDED
130130

131-
# Small delay to ensure the suspension is fully enforced
132-
await asyncio.sleep(1)
133-
134131
# Raise an event and confirm that it does NOT complete while suspended
135132
await c.raise_orchestration_event(id, "my_event", data=42)
136133
try:
137-
state = await c.wait_for_orchestration_completion(id, timeout=5)
134+
state = await c.wait_for_orchestration_completion(id, timeout=3)
138135
assert False, "Orchestration should not have completed"
139136
except TimeoutError:
140137
pass

tests/durabletask/test_orchestration_e2e.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,10 @@ def orchestrator(ctx: task.OrchestrationContext, _):
269269
assert state is not None
270270
assert state.runtime_status == client.OrchestrationStatus.SUSPENDED
271271

272-
# Small delay to ensure the suspension is fully enforced
273-
time.sleep(1)
274-
275272
# Raise an event to the orchestration and confirm that it does NOT complete
276273
task_hub_client.raise_orchestration_event(id, "my_event", data=42)
277274
try:
278-
state = task_hub_client.wait_for_orchestration_completion(id, timeout=5)
275+
state = task_hub_client.wait_for_orchestration_completion(id, timeout=3)
279276
assert False, "Orchestration should not have completed"
280277
except TimeoutError:
281278
pass

0 commit comments

Comments
 (0)