Skip to content

Commit 3dcb003

Browse files
committed
Improve integration tests
Signed-off-by: Tim Li <[email protected]>
1 parent 8dda09d commit 3dcb003

File tree

1 file changed

+52
-84
lines changed

1 file changed

+52
-84
lines changed

tests/integration_tests/test_client.py

Lines changed: 52 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from cadence.error import EntityNotExistsError
77
from tests.integration_tests.helper import CadenceHelper, DOMAIN_NAME
88

9-
109
@pytest.mark.usefixtures("helper")
1110
async def test_domain_exists(helper: CadenceHelper):
1211
async with helper.client() as client:
@@ -33,53 +32,36 @@ async def test_worker_stub_accessible(helper: CadenceHelper):
3332
# Workflow Stub Tests
3433

3534
@pytest.mark.usefixtures("helper")
36-
async def test_workflow_stub_accessible(helper: CadenceHelper):
37-
"""Test that workflow_stub is properly initialized and accessible."""
38-
async with helper.client() as client:
39-
assert client.workflow_stub is not None
40-
# Verify it's the correct type
41-
from cadence.api.v1.service_workflow_pb2_grpc import WorkflowAPIStub
42-
assert isinstance(client.workflow_stub, WorkflowAPIStub)
43-
44-
@pytest.mark.usefixtures("helper")
45-
async def test_workflow_stub_start_workflow(helper: CadenceHelper):
46-
"""Test starting a workflow execution via workflow_stub.
35+
async def test_workflow_stub_start_and_describe(helper: CadenceHelper):
36+
"""Comprehensive test for workflow start and describe operations.
4737
48-
This test verifies that we can start a workflow execution using the
49-
client's start_workflow method, which uses workflow_stub internally.
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
5046
"""
5147
async with helper.client() as client:
52-
# Start a simple workflow
53-
execution = await client.start_workflow(
54-
"test-workflow-type",
55-
task_list="test-task-list",
56-
execution_start_to_close_timeout=timedelta(minutes=5),
57-
workflow_id="test-workflow-id-123",
58-
)
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
5954

60-
# Verify we got a valid execution response
61-
assert execution is not None
62-
assert execution.workflow_id == "test-workflow-id-123"
63-
assert execution.run_id is not None
64-
assert len(execution.run_id) > 0
65-
66-
@pytest.mark.usefixtures("helper")
67-
async def test_workflow_stub_describe_workflow(helper: CadenceHelper):
68-
"""Test describing a workflow execution via workflow_stub.
69-
70-
This test verifies that we can query workflow execution details after
71-
starting a workflow.
72-
"""
73-
async with helper.client() as client:
74-
# First start a workflow
55+
# Start a workflow with specific parameters
7556
execution = await client.start_workflow(
76-
"test-workflow-type-describe",
77-
task_list="test-task-list-describe",
78-
execution_start_to_close_timeout=timedelta(minutes=5),
79-
workflow_id="test-workflow-describe-456",
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,
8062
)
8163

82-
# Now describe the workflow execution
64+
# Describe the workflow execution
8365
describe_request = DescribeWorkflowExecutionRequest(
8466
domain=DOMAIN_NAME,
8567
workflow_execution=WorkflowExecution(
@@ -90,51 +72,37 @@ async def test_workflow_stub_describe_workflow(helper: CadenceHelper):
9072

9173
response = await client.workflow_stub.DescribeWorkflowExecution(describe_request)
9274

93-
# Print the run_id for debugging
94-
print(f"Workflow run_id: {execution.run_id}")
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"
9578

96-
# Verify we got a valid response
97-
assert response is not None
98-
assert response.workflow_execution_info is not None
99-
assert response.workflow_execution_info.workflow_execution.workflow_id == execution.workflow_id
100-
assert response.workflow_execution_info.workflow_execution.run_id == execution.run_id
101-
102-
# Combined Test
103-
104-
@pytest.mark.usefixtures("helper")
105-
async def test_all_stubs_accessible(helper: CadenceHelper):
106-
"""Test that all three stubs (domain, worker, workflow) are accessible.
107-
108-
This is a comprehensive connectivity test that verifies the client
109-
can access all three main API stubs.
110-
"""
111-
async with helper.client() as client:
112-
# Verify all stubs are initialized
113-
assert client.domain_stub is not None
114-
assert client.worker_stub is not None
115-
assert client.workflow_stub is not None
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}"
11685

117-
# Verify they are the correct types
118-
from cadence.api.v1.service_domain_pb2_grpc import DomainAPIStub
119-
from cadence.api.v1.service_worker_pb2_grpc import WorkerAPIStub
120-
from cadence.api.v1.service_workflow_pb2_grpc import WorkflowAPIStub
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}"
12189

122-
assert isinstance(client.domain_stub, DomainAPIStub)
123-
assert isinstance(client.worker_stub, WorkerAPIStub)
124-
assert isinstance(client.workflow_stub, WorkflowAPIStub)
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}"
12593

126-
# Test basic connectivity with each stub
127-
# Domain stub - describe domain
128-
domain_response = await client.domain_stub.DescribeDomain(
129-
DescribeDomainRequest(name=DOMAIN_NAME)
130-
)
131-
assert domain_response.domain.name == DOMAIN_NAME
94+
# Verify execution configuration
95+
assert response.execution_configuration is not None, "execution_configuration is None"
13296

133-
# Workflow stub - start workflow
134-
execution = await client.start_workflow(
135-
"connectivity-test-workflow",
136-
task_list="connectivity-test-task-list",
137-
execution_start_to_close_timeout=timedelta(minutes=5),
138-
workflow_id="connectivity-test-workflow-789",
139-
)
140-
assert execution.workflow_id == "connectivity-test-workflow-789"
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)