Skip to content

Commit 4f63fdb

Browse files
committed
Refactor
1 parent 15c2a1a commit 4f63fdb

1 file changed

Lines changed: 8 additions & 43 deletions

File tree

tests/nexus_sync_operations/nexus_sync_operations_test.py

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import uuid
3+
from typing import Type
34

45
import pytest
56
from temporalio import workflow
@@ -69,47 +70,7 @@ async def test_nexus_sync_operations(client: Client, env: WorkflowEnvironment):
6970
if env.supports_time_skipping:
7071
pytest.skip("Nexus tests don't work under the Java test server")
7172

72-
create_response = await create_nexus_endpoint(
73-
name=NEXUS_ENDPOINT,
74-
task_queue=nexus_sync_operations.handler.worker.TASK_QUEUE,
75-
client=client,
76-
)
77-
try:
78-
await (
79-
nexus_sync_operations.handler.service_handler.GreetingServiceHandler.start(
80-
client, nexus_sync_operations.handler.worker.TASK_QUEUE
81-
)
82-
)
83-
handler_worker_task = asyncio.create_task(
84-
nexus_sync_operations.handler.worker.main(client)
85-
)
86-
try:
87-
async with Worker(
88-
client,
89-
task_queue="test-caller-task-queue",
90-
workflows=[TestCallerWorkflow],
91-
):
92-
await client.execute_workflow(
93-
TestCallerWorkflow.run,
94-
id=str(uuid.uuid4()),
95-
task_queue="test-caller-task-queue",
96-
)
97-
finally:
98-
nexus_sync_operations.handler.worker.interrupt_event.set()
99-
await handler_worker_task
100-
nexus_sync_operations.handler.worker.interrupt_event.clear()
101-
try:
102-
await client.get_workflow_handle(
103-
nexus_sync_operations.handler.service_handler.GreetingServiceHandler.LONG_RUNNING_WORKFLOW_ID
104-
).terminate()
105-
except Exception:
106-
pass
107-
finally:
108-
await delete_nexus_endpoint(
109-
id=create_response.endpoint.id,
110-
version=create_response.endpoint.version,
111-
client=client,
112-
)
73+
await _run_caller_workflow(client, TestCallerWorkflow)
11374

11475

11576
async def test_nexus_sync_operations_caller_workflow(
@@ -121,6 +82,10 @@ async def test_nexus_sync_operations_caller_workflow(
12182
if env.supports_time_skipping:
12283
pytest.skip("Nexus tests don't work under the Java test server")
12384

85+
await _run_caller_workflow(client, CallerWorkflow)
86+
87+
88+
async def _run_caller_workflow(client: Client, workflow: Type):
12489
create_response = await create_nexus_endpoint(
12590
name=NEXUS_ENDPOINT,
12691
task_queue=nexus_sync_operations.handler.worker.TASK_QUEUE,
@@ -139,10 +104,10 @@ async def test_nexus_sync_operations_caller_workflow(
139104
async with Worker(
140105
client,
141106
task_queue="test-caller-task-queue",
142-
workflows=[CallerWorkflow],
107+
workflows=[workflow],
143108
):
144109
await client.execute_workflow(
145-
CallerWorkflow.run,
110+
workflow.run,
146111
id=str(uuid.uuid4()),
147112
task_queue="test-caller-task-queue",
148113
)

0 commit comments

Comments
 (0)