Repository navigation
test(pyamber): add unit tests for _QueueReader and cleanup-failed-upload paths - #4707
Conversation
There was a problem hiding this comment.
Pull request overview
Adds direct unit test coverage for the private _QueueReader helper used by LargeBinaryOutputStream, so queue buffering/partial-read behavior and EOF sentinel handling are validated without spinning up the background upload thread.
Changes:
- Import
_QueueReaderinto the existingtest_large_binary_output_stream.pytest module. - Add a new
TestQueueReadersuite covering chunk joining, partial reads + buffer carryover, EOF behavior, andsize=0. - Add a polling/timeout-path test to exercise the
queue.Emptyretry loop.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4707 +/- ##
============================================
- Coverage 47.57% 43.68% -3.90%
+ Complexity 2149 2075 -74
============================================
Files 817 957 +140
Lines 25980 34067 +8087
Branches 2343 3753 +1410
============================================
+ Hits 12361 14882 +2521
- Misses 12869 18388 +5519
- Partials 750 797 +47
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Addressed in cae19e9: replaced the real-time sleep + background thread with a |
Closes apache#4706 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Replace the real-time sleep + background thread in test_read_polls_until_data_arrives with a MagicMock whose get() side_effect first raises queue.Empty and then yields the data and EOF, so the test no longer depends on CI scheduling timing.
Adds a single test that pins the contract: when the post-failure S3 cleanup itself raises, the original upload IOError must still surface unmasked. Brings large_binary_output_stream.py to 100% line coverage. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
f6c6192 to
709532f
Compare
Both LargeBinaryInputStream and LargeBinaryOutputStream maintained their own self._closed flag in addition to overriding the closed property. The IOBase parent class already tracks closed state, but because we never called super().close(), it never learned we were closed. On Python 3.13 IOBase.__del__ then re-invoked close() during finalization, which on the failed-upload path called _cleanup_failed_upload a second time — driving the test_delete_object_failure_is_swallowed assert_called_once_with failure that only reproduces on 3.13. Drop the redundant flag and property override in both classes; in close(), wrap the existing logic in try/finally and call super().close() in the finally so IOBase records the closed state even when our cleanup raises. Subsequent close() calls (including the implicit one from IOBase's finalizer) now early-return on self.closed and the cleanup runs at most once. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
@kunwp1 please have a look! |
Existing tests reached into the private self._closed attribute that the previous commit removed. Switch them to the public IOBase closed property so they keep verifying the same lifecycle bit without depending on the now-deleted backing field. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
kunwp1
left a comment
There was a problem hiding this comment.
LGTM! Thank you for the fix!
### What changes were proposed in this PR? **What Caused the Issue:** LargeBinaryOutputStream looked up the S3 client twice: once in the upload worker (correct), and once again in close() during failed-upload cleanup. When a test left a stream unclosed, Python's GC eventually called __del__ → close() → the second lookup, but by then a different test was active, so the cleanup hit the wrong test's mock_s3 and broke its assert_called_once_with. **Proposed Fix** - Move `s3.delete_object(...)` from `_cleanup_failed_upload()` into the upload worker, reusing the `s3` client already captured by the closure that did the upload. - Drop the `_cleanup_failed_upload()` method and the call to it from `close()`; the worker now handles cleanup before recording the exception. - `close()` and `__del__` no longer call back into `large_binary_manager`, so a finalizer firing under a later test's monkey-patches cannot reach the wrong S3 client. ### Any related issues, documentation, or discussions? Closes: apache#5245 Follow-up to apache#4707; surfaced on the 3.12 leg of https://github.com/apache/texera/actions/runs/26481776334/job/77980417021. ### How was this PR tested? - Ran `ruff format` and `ruff check` over `amber/src/main/python` and `amber/src/test/python` (clean). - Existing tests in `test_large_binary_output_stream.py` still cover the relevant paths: `test_close_handles_upload_error`, `test_delete_object_failure_is_swallowed`, and `test_write_after_upload_error_raises_error`. - Simplified `test_write_after_upload_error_raises_error` back to inline form and removed the `_drained` helper, both no longer needed once cleanup is structurally contained. ### Was this PR authored or co-authored using generative AI tooling? Co-authored with Claude Opus 4.7 in compliance with ASF --------- Signed-off-by: Matthew B. <[email protected]>
…release/v1.2 backport] (#5602) ### What changes were proposed in this PR? Backport of #5280 ("scope large binary storage and cleanup by execution id") to `release/v1.2`. As noted in #5569, #5280 cannot be backported as a single cherry-pick: its changes to `large_binary_output_stream.py` build on top of #5249 ("keep failed-upload cleanup inside the upload worker"), which is not present on `release/v1.2`. Cherry-picking #5280 alone leaves a dangling reference to the `large_binary_manager` module in `_cleanup_failed_upload()` (a method #5249 removes), producing a `NameError` at runtime. This PR therefore backports the dependency chain, both as clean `git cherry-pick -x` of the original squash commits: 1. **#5249** — keep failed-upload cleanup inside the upload worker (prerequisite) 2. **#5280** — scope large binary storage and cleanup by execution id `#4707` (which #5249 follows up on) is already present on `release/v1.2`, so the chain stops there. After applying both commits, every file touched by #5280 is byte-identical to its state on `main` at the merged #5280 commit (`48e800e4`), and `release/v1.2` had no independent changes to any of those files. ### Any related issues, documentation, discussions? Backports #5280 (which closes #4123 on `main`). Prerequisite: #5249. Unblocks the #5569 backport, which can then cherry-pick cleanly onto `release/v1.2`. ### How was this PR tested? This is a backport with no changes beyond the two cherry-picked commits, so it relies on the existing tests carried over from #5249 and #5280 (`LargeBinaryManagerSpec`, `LargeBinaryManagerUnitSpec`, `test_large_binary_output_stream.py`, `test_large_binary_manager.py`, etc.). Backport fidelity was verified locally by confirming that, after the chain is applied onto `release/v1.2`: - all files touched by #5280 are byte-identical to `main@48e800e`; - no callers of the removed `deleteAllObjects()` remain; - `deleteByExecution` is wired in `WorkflowResource` and `WorkflowService`. Full compile and unit-test runs are left to CI. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Opus 4.8) --------- Signed-off-by: Matthew B. <[email protected]> Signed-off-by: Kunwoo (Chris) <[email protected]> Co-authored-by: Matthew B. <[email protected]> Co-authored-by: Xiaozhen Liu <[email protected]>
…oad paths (apache#4707) ### What changes were proposed in this PR? Adds direct pytest coverage for two pieces of `large_binary_output_stream.py` that previously had only end-to-end coverage: - The private `_QueueReader` helper (partial-read buffering, EOF sentinel handling). - `_cleanup_failed_upload`'s silent-swallow path (when both upload and the post-failure `delete_object` raise). Writing the second test surfaced a real bug, which is also fixed here: `LargeBinaryInputStream` and `LargeBinaryOutputStream` extend `io.IOBase` but maintained their own `self._closed` flag and overrode the `closed` property without ever calling `super().close()`. IOBase's internal closed flag stayed `False`, so on Python 3.13 `IOBase.__del__` re-invoked `close()` during finalization. On the failed-upload path that re-entry called `_cleanup_failed_upload` a second time, sending a duplicate `delete_object` to S3 and tripping `assert_called_once_with` — only on the 3.13 matrix leg. Fix: drop the redundant `self._closed` flag and `closed` property override in both classes; wrap the existing `close()` logic in `try/finally` and call `super().close()` in the `finally`. IOBase now records the closed state even when our cleanup raises, so the implicit finalizer call early-returns on `self.closed` and the cleanup runs at most once. Existing `self._closed` reads (`write`, `writable`, `readable`, `_require_open` decorator) move to `self.closed`. ### Any related issues, documentation, discussions? Closes apache#4706. ### How was this PR tested? ``` cd amber/src/main/python ruff check pytexera/storage/{large_binary_input_stream,large_binary_output_stream,test_large_binary_output_stream}.py ruff format --check pytexera/storage/{large_binary_input_stream,large_binary_output_stream,test_large_binary_output_stream}.py python -m pytest pytexera/storage/test_large_binary_output_stream.py ``` CI exercises the change across the full `python` matrix; before the fix only the 3.13 leg failed on `test_delete_object_failure_is_swallowed`. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Code (claude-opus-4-7)
### What changes were proposed in this PR? **What Caused the Issue:** LargeBinaryOutputStream looked up the S3 client twice: once in the upload worker (correct), and once again in close() during failed-upload cleanup. When a test left a stream unclosed, Python's GC eventually called __del__ → close() → the second lookup, but by then a different test was active, so the cleanup hit the wrong test's mock_s3 and broke its assert_called_once_with. **Proposed Fix** - Move `s3.delete_object(...)` from `_cleanup_failed_upload()` into the upload worker, reusing the `s3` client already captured by the closure that did the upload. - Drop the `_cleanup_failed_upload()` method and the call to it from `close()`; the worker now handles cleanup before recording the exception. - `close()` and `__del__` no longer call back into `large_binary_manager`, so a finalizer firing under a later test's monkey-patches cannot reach the wrong S3 client. ### Any related issues, documentation, or discussions? Closes: apache#5245 Follow-up to apache#4707; surfaced on the 3.12 leg of https://github.com/apache/texera/actions/runs/26481776334/job/77980417021. ### How was this PR tested? - Ran `ruff format` and `ruff check` over `amber/src/main/python` and `amber/src/test/python` (clean). - Existing tests in `test_large_binary_output_stream.py` still cover the relevant paths: `test_close_handles_upload_error`, `test_delete_object_failure_is_swallowed`, and `test_write_after_upload_error_raises_error`. - Simplified `test_write_after_upload_error_raises_error` back to inline form and removed the `_drained` helper, both no longer needed once cleanup is structurally contained. ### Was this PR authored or co-authored using generative AI tooling? Co-authored with Claude Opus 4.7 in compliance with ASF --------- Signed-off-by: Matthew B. <[email protected]>
) ### What changes were proposed in this PR? Remove unused imports, bindings, helpers and fields, and settings that repeat a default or another entry, from the Amber Python runtime, the Python test resources of the workflow compiler and operators, the `bin/` licensing, local-dev and observability scripts, repository configuration, and three GitHub workflows (**+102/-172 lines**). There is no behavior change. - **Amber Python runtime:** `StatisticsManager` uses `defaultdict` instead of the deprecated `typing.DefaultDict`, and `BroadcastPartitioner` builds its batch with `[]`. `LargeBinaryOutputStream` raises and documents `OSError` (which `IOError` aliases), wraps its best-effort cleanup delete in `contextlib.suppress`, and drops the `pass` after `flush`'s docstring. - **Operator verification test resources:** `py_op_driver.py` drops ten `pytexera` imports and `RAW_TYPE_MAPPING` that it never reads. User code runs in its own namespace seeded by `from pytexera import *`, so the "used dynamically" note on those imports did not hold. `compare.py` drops the uncalled `_string_columns` helper and two dict copies of `double_kinds_a`/`double_kinds_e`, and `hf_parse_probe.py` drops unused `io` and `re` imports. Quoted annotations, `open(..., "r")`, `startswith` plus a slice, and a placeholder-free f-string take their plain forms here and in `standalone_worker.py`, `py_compile_worker.py` and `hf_binary_value_probe.py`. - **`bin/` scripts:** the licensing tools use a tuple `startswith`, read the one regex group they need instead of unpacking all four, print plain strings where f-strings had no placeholders, return a `bool` expression directly, drop annotation quotes under `from __future__ import annotations`, use `removesuffix`, and name unused loop values `_`. Two licensing tests drop `# noqa: E402` comments that suppress nothing under Ruff, and `test_local_dev_tui.py` drops the never-passed `version` parameter of `_seed_jvm_layout` together with the docstring sentence about a jar it never wrote. `bin/observability/smoke_test.py` stops returning an unread status from `_post`, builds the trace id from one `uuid4().hex` (the first 32 hex digits of two concatenated ones were always the first), and drops a `leaked = False` that both branches of the following `try` overwrite. - **Repository configuration:** `amber/pyproject.toml` drops `line-length = 88` and `max-complexity = 10`, which are Ruff's defaults (and `C901` is not selected). `.dockerignore` drops a root `user-resources/` entry that its first rule, `**/user-resources/`, already covers. `bin/fix-format.sh` drops the `""` case that `TARGET="${1:-all}"` makes unreachable, and `bin/frontend-proto-gen.sh` drops a `--proto_path` that repeats its `-I`. `bin/k8s/templates/aws/.gitkeep` goes, since the folder holds `s3-credentials-secret.yaml`. `bin/y-websocket-server/package.json` drops npm-init's `main` and placeholder `test` script (the image runs `npx y-websocket`), and a `bin/observability/docker-compose.yml` comment stops pointing at a `start_app.sh` that the repository does not have. - **GitHub workflows:** `comment-commands.yml` drops `github.event_name == 'issue_comment' && github.event.action == 'created'` from three job conditions, because the workflow only runs on `issue_comment: [created]`. `pr-assignment.yml` drops a `|| ''` that follows a `typeof ... === 'string'` guard. `benchmarks-pr-comment.yml` stops storing per-benchmark commit and date, a sample count and delta labels that nothing reads, takes each row's status from the deltas it already computed instead of a second `deltaInfo` pass, reuses each metric's 7-day delta, and builds the PR-only CSV table only when there is no comparison to show. | Event | PR / Commit | | --- | --- | | Introduced by | Amber Python runtime: apache#1891 (2023-05-01), apache#3262 (2025-02-18), apache#4100 (2025-12-15), apache#4707 (2026-05-03), apache#5249 (2026-06-06), apache#8260 (2026-11-18); test resources: apache#7207 (2026-08-14), apache#8617 (2026-10-15), apache#9306 (2026-11-10), apache#8357 (2026-11-17), apache#8358 (2026-11-18), apache#8359 (2026-11-19); `bin/` scripts: apache#4387 (2026-04-29), apache#4668 (2026-05-02), apache#4693 (2026-05-02), apache#4711 (2026-05-03), apache#5057 (2026-05-15), apache#5417 (2026-06-10), apache#5961 (2026-06-28), apache#5377 (2026-10-28); configuration: apache#3019 (2024-11-20), apache#3335 (2025-03-23), apache#3441 (2025-05-19), apache#3890 (2025-10-14), apache#4005 (2025-10-29), apache#4105 (2025-12-05), apache#5757 (2026-06-24); workflows: apache#4885 (2026-05-03), apache#4986 (2026-05-08), apache#5148 (2026-05-22), apache#5557 (2026-06-11), apache#5639 (2026-06-12) | | Usage removed by | `issue_comment` checks: apache#4899 (2026-05-04, `ci: drop the triage label, use is:open no:assignee filter`) moved `/take` out of `issue-triage.yml`, which also ran on `issues` events, into a workflow that only runs on created comments, and apache#4986 and apache#5148 copied the checks into two new jobs; `aws/.gitkeep`: apache#5932 (2026-07-01, `feat(k8s): make app-tier object storage configurable via storage.s3`) added the folder's first template; PR-only CSV table: apache#5639 (2026-06-12, `ci: compare benchmark PRs with main`) shows it only when there is no comparison; everything else: unused or redundant since introduction | As of 2026-11-23, the unread test-resource code is under a week old, the `.gitkeep` placeholder and the unread benchmark fields have been redundant for about 5 months, the `issue_comment` checks for over 6 months, and the duplicate `.dockerignore` entry and `--proto_path` for 20 and 24 months. ### Any related issues, documentation, discussions? Closes apache#9676. ### How was this PR tested? Ran on `525f8ce3fb` and on `main` at `89a492f97e` (Windows 11, Python 3.12 with CI's pinned `ruff` 0.14.7, `pytest` 9.0.3 and `textual` 8.2.8, JDK 17): ```bash cd amber ruff check src/main/python src/test/python ruff format --check src/main/python src/test/python pytest -m "not integration" cd .. ruff check $(git diff --name-only origin/main -- '*.py' ':!amber/') python -m pytest bin/ -v --tb=short sbt "WorkflowCompilingService/testOnly org.apache.texera.amber.translator.verify.ComparatorSpec org.apache.texera.amber.translator.verify.HarnessSpec org.apache.texera.amber.translator.verify.PyOpExecHarnessSpec org.apache.texera.amber.translator.verify.VisualizationJsonComparatorSpec" sbt "WorkflowOperator/testOnly org.apache.texera.amber.operator.huggingFace.codegen.HuggingFaceBinaryValueBehaviorSpec org.apache.texera.amber.operator.huggingFace.codegen.HuggingFaceParseBehaviorSpec org.apache.texera.amber.util.PythonCodeRawInvalidTextSpec" ``` - Ruff: passed on `amber/` (218 files already formatted) and on the 14 changed Python files outside `amber/`. - `pytest -m "not integration"` in `amber/` (JUnit XML): each of the 1,524 tests has the same outcome as on `main`: 1,496 passed, 10 skipped, and the same 18 platform-dependent tests (Iceberg catalog on PostgreSQL and `s3fs`, time zones, object reprs) fail on this Windows machine on both. - `python -m pytest bin/` (JUnit XML): each of the 196 tests has the same outcome as on `main`: 186 passed, and nine `bin/mounter` tests plus `test_stamp_dir_for_matches_shell_sha1`, which assume POSIX paths and shells, fail on Windows on both. - sbt (JUnit XML, `UDF_PYTHON_PATH` set to Python 3.12 because Windows has no `python3`): these seven suites load the edited test resources. `WorkflowCompilingService` passed 52 of 52 in 4 suites and `WorkflowOperator` 11 of 11 in 3 suites, with 0 canceled, the same as on `main`. - Licensing scripts: `concat_license_binary.py` writes byte-identical combined licenses for the Python and frontend images, and `check_binary_deps.py jar` prints byte-identical reports and exit codes for a synthetic lib folder with missing, extra and version-mismatched jars, with and without `--ignore-transitive-version`. - Workflows: the three edited workflows run only from the default branch (`issue_comment`, `pull_request_target` and `workflow_run`), so this PR's CI cannot run them. Each edited `github-script` body ran before and after under Node with recording stubs for `github`, `core`, `fs` and `fetch`, over 496 fixtures (missing or malformed CSV and baseline data, failed API calls, body edits with and without closing references). Every API call, comment body and log line is identical, and a one-line change to each script does show up in its traces. The `comment-commands.yml` conditions differ from `main` only by the two removed checks. - `bash -n` passes on `bin/fix-format.sh` and `bin/frontend-proto-gen.sh`, and the edited YAML, TOML and JSON files parse. - After review, `f84888ca6c` changes only three docstrings in `large_binary_output_stream.py` and inlines one local in `py_op_driver.py`. On it, Ruff passes as above, each of the 1,524 `amber` tests again has the same outcome as on `main`, the four `WorkflowCompilingService` suites pass 52 of 52, and `_jsonify` returns the same strings as on `525f8ce3fb` for seven `BINARY` inputs, with and without the pickle marker. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Opus 5.5)
What changes were proposed in this PR?
Adds direct pytest coverage for two pieces of
large_binary_output_stream.pythat previously had only end-to-end coverage:_QueueReaderhelper (partial-read buffering, EOF sentinel handling)._cleanup_failed_upload's silent-swallow path (when both upload and the post-failuredelete_objectraise).Writing the second test surfaced a real bug, which is also fixed here:
LargeBinaryInputStreamandLargeBinaryOutputStreamextendio.IOBasebut maintained their ownself._closedflag and overrode theclosedproperty without ever callingsuper().close(). IOBase's internal closed flag stayedFalse, so on Python 3.13IOBase.__del__re-invokedclose()during finalization. On the failed-upload path that re-entry called_cleanup_failed_uploada second time, sending a duplicatedelete_objectto S3 and trippingassert_called_once_with— only on the 3.13 matrix leg.Fix: drop the redundant
self._closedflag andclosedproperty override in both classes; wrap the existingclose()logic intry/finallyand callsuper().close()in thefinally. IOBase now records the closed state even when our cleanup raises, so the implicit finalizer call early-returns onself.closedand the cleanup runs at most once. Existingself._closedreads (write,writable,readable,_require_opendecorator) move toself.closed.Any related issues, documentation, discussions?
Closes #4706.
How was this PR tested?
CI exercises the change across the full
pythonmatrix; before the fix only the 3.13 leg failed ontest_delete_object_failure_is_swallowed.Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (claude-opus-4-7)