test(pyamber): add unit tests for replace_print and AtomicInteger#4795
Merged
Conversation
Closes apache#4793 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
aglinxinyuan
approved these changes
May 3, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4795 +/- ##
============================================
+ Coverage 43.62% 43.67% +0.04%
Complexity 2088 2088
============================================
Files 957 957
Lines 34077 34077
Branches 3753 3753
============================================
+ Hits 14865 14882 +17
+ Misses 18419 18401 -18
- Partials 793 794 +1
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:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds pytest coverage for two small pyamber core utilities (AtomicInteger and replace_print) to lock down current behavior and pin a known deadlock bug in AtomicInteger.get_and_set.
Changes:
- Add single-threaded, concurrency, and bug-pinning tests for
core.util.thread.atomic.AtomicInteger(including strict xfail for the intendedget_and_setcontract). - Add lifecycle and payload-shape tests for
core.util.console_message.replace_print.replace_printto validate print interception andConsoleMessagecontents.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| amber/src/main/python/core/util/thread/test_atomic.py | New unit tests for AtomicInteger, including concurrency check and pinned deadlock behavior for get_and_set. |
| amber/src/main/python/core/util/console_message/test_replace_print.py | New unit tests for replace_print context manager lifecycle and ConsoleMessage buffer payload semantics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Previously `completed.wait(timeout=0.5)` returning False could be satisfied by a scheduling delay or by `get_and_set` raising before ever reaching the lock. Track a `started` event set at the top of `attempt`, capture any exception, and assert the worker started, is still alive, and didn't exit due to an error before checking that `completed` is unset. The pin now actually proves the deadlock path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this PR?
Adds pytest coverage for two thin core utilities:
amber/src/main/python/core/util/console_message/replace_print.py— thereplace_printcontext manager that interceptsbuiltins.printand enqueuesConsoleMessagepayloads on a buffer.amber/src/main/python/core/util/thread/atomic.py— theAtomicIntegerthread-safe counter.Any related issues, documentation, discussions?
Closes #4793.
Bug pinned in the spec with comment + xfail-strict for the intended contract (filed separately as a Bug issue):
AtomicInteger.get_and_setdeadlocks because it holds the non-reentrant lock while invoking thevalueproperty, which tries to acquire the same lock again. The pinned test surfaces the deadlock via a thread + timeout (so the suite does not hang), and the xfail-strict companion asserts the intendedget_and_setcontract — that test will flip to XPASS the moment the deadlock is fixed and force the spec to be updated alongside.How was this PR tested?
Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (claude-opus-4-7)