feat(test): activity test environment#151
Conversation
Signed-off-by: Shijie Sheng <liouvetren@gmail.com>
| self._thread_pool = ThreadPoolExecutor( | ||
| max_workers=1, thread_name_prefix="cadence-test-activity" | ||
| ) |
There was a problem hiding this comment.
💡 Edge Case: Timeout on non-cooperative sync activity leaks the worker thread
The thread pool is created with max_workers=1, and the set_test_timeout path cancels the asyncio task wrapping context.execute. For a sync activity, execution runs via loop.run_in_executor on that single thread; cancelling the awaiting coroutine does not stop the underlying blocking thread. After a timeout on a sync activity, the thread stays occupied and close() uses shutdown(wait=False), so the thread leaks and any subsequent execute_activity on the same env blocks forever waiting for a free worker. Only async timeouts are covered by tests. Consider documenting this limitation, or noting in set_test_timeout that sync activities that ignore is_cancelled() cannot be interrupted.
Was this helpful? React with 👍 / 👎
| def set_heartbeat_details(self, *details: Any) -> None: | ||
| """Seed the details returned from ``activity.heartbeat_details()``. | ||
|
|
||
| Mirrors Go's ``SetHeartbeatDetails`` and simulates a retry where the | ||
| server hands back the details recorded by a previous attempt. | ||
| """ | ||
| self._seeded_heartbeat_details = self._data_converter.to_data(list(details)) |
There was a problem hiding this comment.
💡 Quality: Confusingly similar set_heartbeat_details vs get_heartbeat_details
set_heartbeat_details seeds the values that the activity reads back via activity.heartbeat_details() (simulated prior-attempt input), while get_heartbeat_details returns the details the activity emitted via activity.heartbeat() during this run (output). The near-identical names obscure that they operate on opposite data flows. Consider renaming get_heartbeat_details to something like get_last_heartbeat_details / get_recorded_heartbeat_details, or clarifying the distinction more prominently in the docstrings.
Was this helpful? React with 👍 / 👎
CI failed: The CI build failed due to a code formatting violation in a newly added file. The linting step identified that 'cadence/testing/_activity_environment.py' does not match the project's style requirements.OverviewThe build failed in the linting/formatting stage because a file added in this PR does not conform to the project's formatting standards. 1 log was analyzed and confirmed that the CI exited with code 1 due to this formatting mismatch. FailuresFormatting Violation (confidence: high)
Summary
Code Review 👍 Approved with suggestions 0 resolved / 2 findingsIntroduces 💡 Edge Case: Timeout on non-cooperative sync activity leaks the worker thread📄 cadence/testing/_activity_environment.py:175-177 📄 cadence/testing/_activity_environment.py:288-302 The thread pool is created with max_workers=1, and the set_test_timeout path cancels the asyncio task wrapping context.execute. For a sync activity, execution runs via loop.run_in_executor on that single thread; cancelling the awaiting coroutine does not stop the underlying blocking thread. After a timeout on a sync activity, the thread stays occupied and close() uses shutdown(wait=False), so the thread leaks and any subsequent execute_activity on the same env blocks forever waiting for a free worker. Only async timeouts are covered by tests. Consider documenting this limitation, or noting in set_test_timeout that sync activities that ignore is_cancelled() cannot be interrupted. 💡 Quality: Confusingly similar set_heartbeat_details vs get_heartbeat_details📄 cadence/testing/_activity_environment.py:200-206 📄 cadence/testing/_activity_environment.py:232-245 set_heartbeat_details seeds the values that the activity reads back via activity.heartbeat_details() (simulated prior-attempt input), while get_heartbeat_details returns the details the activity emitted via activity.heartbeat() during this run (output). The near-identical names obscure that they operate on opposite data flows. Consider renaming get_heartbeat_details to something like get_last_heartbeat_details / get_recorded_heartbeat_details, or clarifying the distinction more prominently in the docstrings. 🤖 Prompt for agentsTip Comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
Codecov Report❌ Patch coverage is
🚀 New features to boost your workflow:
|
| _TASK_TOKEN = b"test-task-token" | ||
|
|
||
|
|
||
| class _FakeWorkerStub: |
There was a problem hiding this comment.
nit: instead of fakeworkerstub, SimulatedWorkerStub might be a better name here since we are simulating a worker grpc stub.
What changed?
Why?
How did you test it?
Potential risks
Release notes
Documentation Changes