From 9313bd8f0badccee2456f25d41e2c74884701c00 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Mon, 26 Aug 2024 12:37:49 -0400 Subject: [PATCH] Failing test --- tests/test_client.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/test_client.py b/tests/test_client.py index 3c41409d..3239c32f 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -5,10 +5,15 @@ from datetime import datetime, timedelta, timezone from typing import Any, List, Optional, Tuple, cast +import google.protobuf.any_pb2 +import google.protobuf.message import pytest from google.protobuf import json_format +import temporalio.api.common.v1 import temporalio.api.enums.v1 +import temporalio.api.errordetails.v1 +import temporalio.api.workflowservice.v1 import temporalio.common import temporalio.exceptions from temporalio import workflow @@ -80,6 +85,7 @@ ) from temporalio.converter import DataConverter from temporalio.exceptions import WorkflowAlreadyStartedError +from temporalio.service import ServiceCall from temporalio.testing import WorkflowEnvironment from tests.helpers import ( assert_eq_eventually, @@ -283,6 +289,39 @@ async def test_terminate(client: Client, worker: ExternalWorker): assert list(err.value.cause.details) == ["arg1", "arg2"] +async def test_rpc_already_exists_error_is_raised(client: Client): + class start_workflow_execution( + ServiceCall[ + temporalio.api.workflowservice.v1.StartWorkflowExecutionRequest, + temporalio.api.workflowservice.v1.StartWorkflowExecutionResponse, + ] + ): + already_exists_err = RPCError( + "fake already exists error", RPCStatusCode.ALREADY_EXISTS, b"" + ) + already_exists_err._grpc_status = temporalio.api.common.v1.GrpcStatus( + details=[ + google.protobuf.any_pb2.Any( + type_url="not-WorkflowExecutionAlreadyStartedFailure", value=b"" + ) + ], + ) + + def __init__(self) -> None: + pass + + async def __call__(self, *args, **kwargs) -> google.protobuf.message.Message: + raise self.already_exists_err + + workflow_service: temporalio.service.WorkflowService = ( + client._impl._client.workflow_service # type: ignore + ) + workflow_service.start_workflow_execution = start_workflow_execution() + with pytest.raises(RPCError) as err: + await client.start_workflow("fake", id="fake", task_queue="fake") + assert err.value.status == RPCStatusCode.ALREADY_EXISTS + + async def test_cancel_not_found(client: Client): with pytest.raises(RPCError) as err: await client.get_workflow_handle("does-not-exist").cancel()