Skip to content

Commit 2121489

Browse files
authored
chore: add integration tests for start_workflow client method (#38)
<!-- Describe what has changed in this PR --> **What changed?** Add integration tests for start_workflow client method <!-- Tell your future self why have you made these changes --> **Why?** The integration tests check if the request was successfully made and received by cadence server <!-- How have you verified this change? Tested locally? Added a unit test? Checked in staging env? --> **How did you test it?** It's only test <!-- Assuming the worst case, what can be broken when deploying this change to production? --> **Potential risks** <!-- Is it notable for release? e.g. schema updates, configuration or data migration required? If so, please mention it, and also update CHANGELOG.md --> **Release notes** <!-- Is there any documentation updates should be made for config, https://cadenceworkflow.io/docs/operation-guide/setup/ ? If so, please open an PR in https://github.com/cadence-workflow/cadence-docs --> **Documentation Changes** --------- Signed-off-by: Tim Li <[email protected]>
1 parent 2d2accb commit 2121489

File tree

1 file changed

+92
-2
lines changed

1 file changed

+92
-2
lines changed

tests/integration_tests/test_client.py

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
from datetime import timedelta
12
import pytest
2-
33
from cadence.api.v1.service_domain_pb2 import DescribeDomainRequest, DescribeDomainResponse
4+
from cadence.api.v1.service_workflow_pb2 import DescribeWorkflowExecutionRequest
5+
from cadence.api.v1.common_pb2 import WorkflowExecution
46
from cadence.error import EntityNotExistsError
57
from tests.integration_tests.helper import CadenceHelper, DOMAIN_NAME
68

7-
89
@pytest.mark.usefixtures("helper")
910
async def test_domain_exists(helper: CadenceHelper):
1011
async with helper.client() as client:
@@ -16,3 +17,92 @@ async def test_domain_not_exists(helper: CadenceHelper):
1617
with pytest.raises(EntityNotExistsError):
1718
async with helper.client() as client:
1819
await client.domain_stub.DescribeDomain(DescribeDomainRequest(name="unknown-domain"))
20+
21+
# Worker Stub Tests
22+
23+
@pytest.mark.usefixtures("helper")
24+
async def test_worker_stub_accessible(helper: CadenceHelper):
25+
"""Test that worker_stub is properly initialized and accessible."""
26+
async with helper.client() as client:
27+
assert client.worker_stub is not None
28+
# Verify it's the correct type
29+
from cadence.api.v1.service_worker_pb2_grpc import WorkerAPIStub
30+
assert isinstance(client.worker_stub, WorkerAPIStub)
31+
32+
# Workflow Stub Tests
33+
34+
@pytest.mark.usefixtures("helper")
35+
async def test_workflow_stub_start_and_describe(helper: CadenceHelper):
36+
"""Comprehensive test for workflow start and describe operations.
37+
38+
This integration test verifies:
39+
1. Starting a workflow execution via workflow_stub
40+
2. Describing the workflow execution
41+
3. All parameters match between start request and describe response:
42+
- workflow_id and run_id
43+
- workflow type
44+
- task list configuration
45+
- execution and task timeouts
46+
"""
47+
async with helper.client() as client:
48+
# Define workflow parameters
49+
workflow_type = "test-workflow-type-describe"
50+
task_list_name = "test-task-list-describe"
51+
workflow_id = "test-workflow-describe-456"
52+
execution_timeout = timedelta(minutes=5)
53+
task_timeout = timedelta(seconds=10) # Default value
54+
55+
# Start a workflow with specific parameters
56+
execution = await client.start_workflow(
57+
workflow_type,
58+
task_list=task_list_name,
59+
execution_start_to_close_timeout=execution_timeout,
60+
task_start_to_close_timeout=task_timeout,
61+
workflow_id=workflow_id,
62+
)
63+
64+
# Describe the workflow execution
65+
describe_request = DescribeWorkflowExecutionRequest(
66+
domain=DOMAIN_NAME,
67+
workflow_execution=WorkflowExecution(
68+
workflow_id=execution.workflow_id,
69+
run_id=execution.run_id,
70+
),
71+
)
72+
73+
response = await client.workflow_stub.DescribeWorkflowExecution(describe_request)
74+
75+
# Assert workflow execution info matches
76+
assert response is not None, "DescribeWorkflowExecution returned None"
77+
assert response.workflow_execution_info is not None, "workflow_execution_info is None"
78+
79+
# Verify workflow execution identifiers
80+
wf_exec = response.workflow_execution_info.workflow_execution
81+
assert wf_exec.workflow_id == workflow_id, \
82+
f"workflow_id mismatch: expected {workflow_id}, got {wf_exec.workflow_id}"
83+
assert wf_exec.run_id == execution.run_id, \
84+
f"run_id mismatch: expected {execution.run_id}, got {wf_exec.run_id}"
85+
86+
# Verify workflow type
87+
assert response.workflow_execution_info.type.name == workflow_type, \
88+
f"workflow_type mismatch: expected {workflow_type}, got {response.workflow_execution_info.type.name}"
89+
90+
# Verify task list
91+
assert response.workflow_execution_info.task_list == task_list_name, \
92+
f"task_list mismatch: expected {task_list_name}, got {response.workflow_execution_info.task_list}"
93+
94+
# Verify execution configuration
95+
assert response.execution_configuration is not None, "execution_configuration is None"
96+
97+
# Verify task list in configuration
98+
assert response.execution_configuration.task_list.name == task_list_name, \
99+
f"config task_list mismatch: expected {task_list_name}, got {response.execution_configuration.task_list.name}"
100+
101+
# Verify timeouts
102+
exec_timeout_seconds = response.execution_configuration.execution_start_to_close_timeout.ToSeconds()
103+
assert exec_timeout_seconds == execution_timeout.total_seconds(), \
104+
f"execution_start_to_close_timeout mismatch: expected {execution_timeout.total_seconds()}s, got {exec_timeout_seconds}s"
105+
106+
task_timeout_seconds = response.execution_configuration.task_start_to_close_timeout.ToSeconds()
107+
assert task_timeout_seconds == task_timeout.total_seconds(), \
108+
f"task_start_to_close_timeout mismatch: expected {task_timeout.total_seconds()}s, got {task_timeout_seconds}s"

0 commit comments

Comments
 (0)