feat(test): activity test environment - #151
Conversation
| 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 👍 / 👎
There was a problem hiding this comment.
will address in the new PR
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.
Signed-off-by: Shijie Sheng <liouvetren@gmail.com>
Signed-off-by: Shijie Sheng <liouvetren@gmail.com>
cbe8707 to
61930c3
Compare
Code Review 👍 Approved with suggestions 1 resolved / 2 findingsAdds a new TestActivityEnvironment utility to enable standalone unit testing of sync and async activities. Consider addressing the thread leak in non-cooperative sync activity timeouts. 💡 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. ✅ 1 resolved✅ Quality: Confusingly similar set_heartbeat_details vs get_heartbeat_details
🤖 Prompt for agentsOptionsAuto-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 |
What changed?
Why?
How did you test it?
Potential risks
Release notes
Documentation Changes