Skip to content

Commit f30a7fa

Browse files
committed
Update test
1 parent 790a0c0 commit f30a7fa

File tree

1 file changed

+56
-19
lines changed

1 file changed

+56
-19
lines changed

tests/nexus/test_workflow_caller.py

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import uuid
33
from dataclasses import dataclass
44
from enum import IntEnum
5+
from itertools import zip_longest
56
from typing import Any, Callable, Literal, Union
67

78
import nexusrpc
@@ -1164,12 +1165,34 @@ async def assert_handler_workflow_has_link_to_caller_workflow(
11641165
# io.temporal.failure.ApplicationFailure(type=no-type-attr, message=message='application error 1', type='APPLICATION_ERROR', nonRetryable=true)
11651166
# io.temporal.failure.ApplicationFailure(type=no-type-attr, message=message='Custom error 2', type='io.temporal.samples.nexus.handler.NexusServiceImpl$MyCustomException', nonRetryable=false)
11661167

1168+
ActionInSyncOp = Literal[
1169+
"application_error_non_retryable",
1170+
"custom_error",
1171+
"custom_error_from_custom_error",
1172+
"application_error_non_retryable_from_custom_error",
1173+
"nexus_handler_error_not_found",
1174+
"nexus_handler_error_not_found_from_custom_error",
1175+
"nexus_operation_error_from_application_error_non_retryable_from_custom_error",
1176+
]
1177+
11671178

11681179
@dataclass
11691180
class ErrorConversionTestCase:
1170-
name: str
1181+
name: ActionInSyncOp
11711182
java_behavior: list[tuple[type[Exception], dict[str, Any]]]
11721183

1184+
@staticmethod
1185+
def parse_exception(
1186+
exception: BaseException,
1187+
) -> tuple[type[BaseException], dict[str, Any]]:
1188+
if isinstance(exception, NexusOperationError):
1189+
return NexusOperationError, {}
1190+
return type(exception), {
1191+
"message": getattr(exception, "message", None),
1192+
"type": getattr(exception, "type", None),
1193+
"non_retryable": getattr(exception, "non_retryable", None),
1194+
}
1195+
11731196

11741197
error_conversion_test_cases = []
11751198

@@ -1247,6 +1270,13 @@ class ErrorConversionTestCase:
12471270
_ = ["NexusOperationError", "HandlerError"]
12481271
# Java
12491272
# [Not possible]
1273+
error_conversion_test_cases.append(
1274+
ErrorConversionTestCase(
1275+
name="custom_error_from_custom_error",
1276+
java_behavior=[], # [Not possible]
1277+
)
1278+
)
1279+
12501280

12511281
# application_error_non_retryable_from_custom_error:
12521282
_ = ["NexusOperationError", "HandlerError"]
@@ -1302,7 +1332,7 @@ class ErrorConversionTestCase:
13021332

13031333
error_conversion_test_cases.append(
13041334
ErrorConversionTestCase(
1305-
name="application_error_non_retryable_from_custom_error",
1335+
name="nexus_handler_error_not_found",
13061336
java_behavior=[
13071337
(NexusOperationError, {}),
13081338
(
@@ -1331,7 +1361,7 @@ class ErrorConversionTestCase:
13311361
# [Not possible]
13321362
error_conversion_test_cases.append(
13331363
ErrorConversionTestCase(
1334-
name="nexus_handler_error_not_found",
1364+
name="nexus_handler_error_not_found_from_custom_error",
13351365
java_behavior=[], # [Not possible]
13361366
)
13371367
)
@@ -1371,17 +1401,6 @@ class ErrorConversionTestCase:
13711401
)
13721402

13731403

1374-
ActionInSyncOp = Literal[
1375-
"application_error_non_retryable",
1376-
"custom_error",
1377-
"custom_error_from_custom_error",
1378-
"application_error_non_retryable_from_custom_error",
1379-
"nexus_handler_error_not_found",
1380-
"nexus_handler_error_not_found_from_custom_error",
1381-
"nexus_operation_error_from_application_error_non_retryable_from_custom_error",
1382-
]
1383-
1384-
13851404
class CustomError(Exception):
13861405
pass
13871406

@@ -1453,9 +1472,10 @@ def __init__(self, input: ErrorTestInput):
14531472
service=ErrorTestService,
14541473
endpoint=make_nexus_endpoint_name(input.task_queue),
14551474
)
1475+
self.test_cases = {t.name: t for t in error_conversion_test_cases}
14561476

14571477
@workflow.run
1458-
async def run(self, input: ErrorTestInput) -> list[str]:
1478+
async def run(self, input: ErrorTestInput) -> None:
14591479
try:
14601480
await self.nexus_client.execute_operation(
14611481
# TODO(nexus-preview): why wasn't this a type error?
@@ -1470,7 +1490,26 @@ async def run(self, input: ErrorTestInput) -> list[str]:
14701490
while err.__cause__:
14711491
errs.append(err.__cause__)
14721492
err = err.__cause__
1473-
return [type(err).__name__ for err in errs]
1493+
actual = [ErrorConversionTestCase.parse_exception(err) for err in errs]
1494+
results = list(
1495+
zip_longest(
1496+
self.test_cases[input.action_in_sync_op].java_behavior,
1497+
actual,
1498+
fillvalue=None,
1499+
)
1500+
)
1501+
print(f"""
1502+
1503+
{input.action_in_sync_op}
1504+
{'-' * 80}
1505+
""")
1506+
for java_behavior, actual in results:
1507+
print(f"Java: {java_behavior}")
1508+
print(f"Python: {actual}")
1509+
print()
1510+
print("-" * 80)
1511+
return None
1512+
14741513
assert False, "Unreachable"
14751514

14761515

@@ -1497,7 +1536,7 @@ async def test_errors_raised_by_nexus_operation(
14971536
task_queue=task_queue,
14981537
):
14991538
await create_nexus_endpoint(task_queue, client)
1500-
result = await client.execute_workflow(
1539+
await client.execute_workflow(
15011540
ErrorTestCallerWorkflow.run,
15021541
ErrorTestInput(
15031542
task_queue=task_queue,
@@ -1506,5 +1545,3 @@ async def test_errors_raised_by_nexus_operation(
15061545
id=str(uuid.uuid4()),
15071546
task_queue=task_queue,
15081547
)
1509-
1510-
print(f"\n\n\n{action_in_sync_op}: \n", result, "\n\n\n")

0 commit comments

Comments
 (0)