Skip to content

Commit

Permalink
Relocate test to sandbox-friendly file
Browse files Browse the repository at this point in the history
  • Loading branch information
dandavison committed Aug 19, 2024
1 parent 9994a1d commit f2902ec
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 45 deletions.
45 changes: 0 additions & 45 deletions tests/worker/test_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
Worker,
WorkerConfig,
)
from tests.helpers import new_worker
from tests.helpers.worker import (
ExternalWorker,
KSAction,
Expand Down Expand Up @@ -1352,47 +1351,3 @@ def assert_activity_application_error(
ret = assert_activity_error(err)
assert isinstance(ret, ApplicationError)
return ret


@activity.defn
async def activity_with_retry_delay():
raise ApplicationError(
ActivitiesWithRetryDelayWorkflow.error_message,
next_retry_delay=ActivitiesWithRetryDelayWorkflow.next_retry_delay,
)


@workflow.defn
class ActivitiesWithRetryDelayWorkflow:
error_message = "Deliberately failing with next_retry_delay set"
next_retry_delay = timedelta(milliseconds=5)

@workflow.run
async def run(self) -> None:
await workflow.execute_activity(
activity_with_retry_delay,
retry_policy=RetryPolicy(maximum_attempts=2),
schedule_to_close_timeout=self.next_retry_delay,
)


async def test_activity_retry_delay(client: Client):
async with new_worker(
client, ActivitiesWithRetryDelayWorkflow, activities=[activity_with_retry_delay]
) as worker:
try:
await client.execute_workflow(
ActivitiesWithRetryDelayWorkflow.run,
id=str(uuid.uuid4()),
task_queue=worker.task_queue,
)
except WorkflowFailureError as err:
assert isinstance(err.cause, ActivityError)
assert isinstance(err.cause.cause, ApplicationError)
assert (
str(err.cause.cause) == ActivitiesWithRetryDelayWorkflow.error_message
)
assert (
err.cause.cause.next_retry_delay
== ActivitiesWithRetryDelayWorkflow.next_retry_delay
)
44 changes: 44 additions & 0 deletions tests/worker/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5861,3 +5861,47 @@ async def test_timer_started_after_workflow_completion(client: Client):
)
await handle.signal(TimerStartedAfterWorkflowCompletionWorkflow.my_signal)
assert await handle.result() == "workflow-result"


@activity.defn
async def activity_with_retry_delay():
raise ApplicationError(
ActivitiesWithRetryDelayWorkflow.error_message,
next_retry_delay=ActivitiesWithRetryDelayWorkflow.next_retry_delay,
)


@workflow.defn
class ActivitiesWithRetryDelayWorkflow:
error_message = "Deliberately failing with next_retry_delay set"
next_retry_delay = timedelta(milliseconds=5)

@workflow.run
async def run(self) -> None:
await workflow.execute_activity(
activity_with_retry_delay,
retry_policy=RetryPolicy(maximum_attempts=2),
schedule_to_close_timeout=self.next_retry_delay,
)


async def test_activity_retry_delay(client: Client):
async with new_worker(
client, ActivitiesWithRetryDelayWorkflow, activities=[activity_with_retry_delay]
) as worker:
try:
await client.execute_workflow(
ActivitiesWithRetryDelayWorkflow.run,
id=str(uuid.uuid4()),
task_queue=worker.task_queue,
)
except WorkflowFailureError as err:
assert isinstance(err.cause, ActivityError)
assert isinstance(err.cause.cause, ApplicationError)
assert (
str(err.cause.cause) == ActivitiesWithRetryDelayWorkflow.error_message
)
assert (
err.cause.cause.next_retry_delay
== ActivitiesWithRetryDelayWorkflow.next_retry_delay
)

0 comments on commit f2902ec

Please sign in to comment.