|
3 | 3 | import os
|
4 | 4 | import uuid
|
5 | 5 | from datetime import datetime, timedelta, timezone
|
6 |
| -from typing import Any, List, Optional, Tuple, cast |
| 6 | +from typing import Any, List, Mapping, Optional, Tuple, cast |
| 7 | +from unittest import mock |
7 | 8 |
|
| 9 | +import google.protobuf.any_pb2 |
| 10 | +import google.protobuf.message |
8 | 11 | import pytest
|
9 | 12 | from google.protobuf import json_format
|
10 | 13 |
|
| 14 | +import temporalio.api.common.v1 |
11 | 15 | import temporalio.api.enums.v1
|
| 16 | +import temporalio.api.errordetails.v1 |
| 17 | +import temporalio.api.workflowservice.v1 |
12 | 18 | import temporalio.common
|
13 | 19 | import temporalio.exceptions
|
14 | 20 | from temporalio import workflow
|
|
80 | 86 | )
|
81 | 87 | from temporalio.converter import DataConverter
|
82 | 88 | from temporalio.exceptions import WorkflowAlreadyStartedError
|
| 89 | +from temporalio.service import ServiceCall |
83 | 90 | from temporalio.testing import WorkflowEnvironment
|
84 | 91 | from tests.helpers import (
|
85 | 92 | assert_eq_eventually,
|
@@ -283,6 +290,45 @@ async def test_terminate(client: Client, worker: ExternalWorker):
|
283 | 290 | assert list(err.value.cause.details) == ["arg1", "arg2"]
|
284 | 291 |
|
285 | 292 |
|
| 293 | +async def test_rpc_already_exists_error_is_raised(client: Client): |
| 294 | + class start_workflow_execution( |
| 295 | + ServiceCall[ |
| 296 | + temporalio.api.workflowservice.v1.StartWorkflowExecutionRequest, |
| 297 | + temporalio.api.workflowservice.v1.StartWorkflowExecutionResponse, |
| 298 | + ] |
| 299 | + ): |
| 300 | + already_exists_err = RPCError( |
| 301 | + "fake already exists error", RPCStatusCode.ALREADY_EXISTS, b"" |
| 302 | + ) |
| 303 | + already_exists_err._grpc_status = temporalio.api.common.v1.GrpcStatus( |
| 304 | + details=[ |
| 305 | + google.protobuf.any_pb2.Any( |
| 306 | + type_url="not-WorkflowExecutionAlreadyStartedFailure", value=b"" |
| 307 | + ) |
| 308 | + ], |
| 309 | + ) |
| 310 | + |
| 311 | + def __init__(self) -> None: |
| 312 | + pass |
| 313 | + |
| 314 | + async def __call__( |
| 315 | + self, |
| 316 | + req: temporalio.api.workflowservice.v1.StartWorkflowExecutionRequest, |
| 317 | + *, |
| 318 | + retry: bool = False, |
| 319 | + metadata: Mapping[str, str] = {}, |
| 320 | + timeout: Optional[timedelta] = None, |
| 321 | + ) -> temporalio.api.workflowservice.v1.StartWorkflowExecutionResponse: |
| 322 | + raise self.already_exists_err |
| 323 | + |
| 324 | + with mock.patch.object( |
| 325 | + client.workflow_service, "start_workflow_execution", start_workflow_execution() |
| 326 | + ): |
| 327 | + with pytest.raises(RPCError) as err: |
| 328 | + await client.start_workflow("fake", id="fake", task_queue="fake") |
| 329 | + assert err.value.status == RPCStatusCode.ALREADY_EXISTS |
| 330 | + |
| 331 | + |
286 | 332 | async def test_cancel_not_found(client: Client):
|
287 | 333 | with pytest.raises(RPCError) as err:
|
288 | 334 | await client.get_workflow_handle("does-not-exist").cancel()
|
|
0 commit comments