You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add context manager support to TaskHubGrpcClient (#145)
* Add context manager support to TaskHubGrpcClient (#134)
Add `__enter__`/`__exit__` to the sync `TaskHubGrpcClient` so callers can
use it with a `with` statement, mirroring the existing
`AsyncTaskHubGrpcClient` async-context-manager support and the
`TaskHubGrpcWorker` pattern. `DurableTaskSchedulerClient` inherits this
behavior automatically.
`__exit__` delegates to `close()`, so the resiliency-aware teardown
introduced in #135 (in-flight recreate thread join, retired-channel
timer cancellation, SDK-owned channel cleanup) runs unchanged through
the new `with` path. Caller-owned channels remain untouched.
Migrate every test and example callsite that previously instantiated
`TaskHubGrpcClient(...)` and never closed it to the `with` form so the
gRPC channel is deterministically released. Unit tests in
`test_client.py` that intentionally test construction (with mocked
stubs) are left unchanged.
Add focused unit tests for the new context-manager behavior, including
a regression test that exits a `with` block while a fire-and-forget
channel recreate is pending and asserts the #135 resiliency invariants
(retired-channel timers cancelled, recreate thread joined) still hold.
Fixes#134
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Address auto-generated code-quality review comments on PR #145
1. tests/durabletask/test_orchestration_e2e.py (test_suspend_and_resume):
Drop the unused `state =` assignment around the expected-timeout
`wait_for_orchestration_completion` call. The value is never read
because the next line asserts False and the only non-failing path
raises TimeoutError; `state` is reassigned a few lines down. Silences
the "variable defined multiple times" warning that CodeQL flagged
because this previously-untouched line was pulled into the diff by
the indent change.
2. tests/durabletask/test_client.py
(test_sync_client_context_manager_propagates_exception_and_calls_close):
Replace the nested `with pytest.raises(...): with client: raise ...`
pattern with an explicit try/except so CodeQL no longer reports the
post-block assertions as unreachable. Test intent (exception
propagation + cleanup verification) is preserved.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Align __exit__ typing with repo convention (BlobPayloadStore)
Use `*args: object` for the `__exit__` parameters instead of leaving
them untyped. This matches the most recent context-manager class in
the repo (`durabletask/extensions/azure_blob_payloads/blob_payload_store.py`),
is more type-safe under Pylance/mypy, and avoids the parameter
shadowing of the builtin `type` that exists in
`TaskHubGrpcWorker.__exit__`. Behavior is unchanged.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Align pre-existing context manager methods with repo idiom
Apply the same `__enter__`/`__exit__` typing pattern that PR #145 uses
for `TaskHubGrpcClient` (and that `BlobPayloadStore` already follows)
to three pre-existing context managers that were either untyped or
shadowed a builtin:
* `AsyncTaskHubGrpcClient.__aenter__` now returns the concrete type and
`__aexit__` takes `*args: object` with `-> None`.
* `TaskHubGrpcWorker.__enter__/__exit__` get the same treatment, also
removing the `type` parameter that shadowed the builtin.
* `EntityLock.__enter__/__exit__` get the same treatment; the file
already has `from __future__ import annotations` so the return
annotation is the bare class name.
Behavior is unchanged: each `__exit__` still delegates to its existing
teardown method (`close`/`stop`/`_exit_critical_section`), so the
gRPC resiliency teardown added in PR #135 continues to flow through
`TaskHubGrpcClient.close()` unchanged.
No changelog entry: per the repo's contributor guidance, internal-only
type-annotation refactors with no externally observable behavior change
are excluded from the changelog.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Bernd Verst <beverst@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
0 commit comments