Skip to content

test(pyamber): add unit tests for six DP-thread state managers#4893

Merged
aglinxinyuan merged 3 commits into
apache:mainfrom
Yicong-Huang:test-pyamber-managers
May 4, 2026
Merged

test(pyamber): add unit tests for six DP-thread state managers#4893
aglinxinyuan merged 3 commits into
apache:mainfrom
Yicong-Huang:test-pyamber-managers

Conversation

@Yicong-Huang
Copy link
Copy Markdown
Contributor

@Yicong-Huang Yicong-Huang commented May 4, 2026

What changes were proposed in this PR?

Adds pytest specs for six DP-thread state managers under amber/src/main/python/core/architecture/managers/: state_processing_manager, exception_manager, console_message_manager, tuple_processing_manager, statistics_manager, and embedded_control_message_manager. The specs cover the consume-once read pattern, accumulator validation, force-flush semantics, and the three ECM alignment modes (ALL / NO / PORT) including scope filtering.

Pinned a real-but-questionable behavior in StatisticsManager.get_statistics() where idle_time goes negative when data + control processing time overshoots total_execution_time, paired with an xfail(strict=True) probe asserting the intended >= 0 contract.

Any related issues, documentation, discussions?

Closes #4891. Bug filed as #4892 (xfail probe will flip to XPASS when fixed).

How was this PR tested?

New pytest cases (44 passing + 1 xfailed) under core/architecture/managers/. Verified locally with python -m pytest core/architecture/managers/ and ruff format --check amber/src/main/python.

Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Opus 4.7 (1M context)

Cover the consume-once / accumulator / alignment contracts for
state_processing, exception, console-message, tuple-processing,
statistics, and embedded-control-message managers.

Issue apache#4891

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 43.77%. Comparing base (aedc6e2) to head (4879aa1).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4893      +/-   ##
============================================
+ Coverage     43.15%   43.77%   +0.62%     
+ Complexity     2153     2087      -66     
============================================
  Files           915      957      +42     
  Lines         32208    34066    +1858     
  Branches       3256     3753     +497     
============================================
+ Hits          13898    14914    +1016     
- Misses        17464    18357     +893     
+ Partials        846      795      -51     
Flag Coverage Δ
python 87.41% <ø> (+0.45%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds focused pytest unit coverage for several DP-thread “manager” components in PyAmber, ensuring core state/metrics/control-message behaviors are pinned and regression-protected.

Changes:

  • Added consume-once / slot-clearing contract tests for state, tuple, and exception managers.
  • Added statistics aggregation/validation tests, including an xfail(strict=True) probe for the known negative idle_time bug.
  • Added console-buffer and embedded-control-message (ECM) alignment/scope tests across ALL / NO / PORT alignment modes.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
amber/src/main/python/core/architecture/managers/test_state_processing_manager.py Tests consume-once semantics and independence of input/output state slots.
amber/src/main/python/core/architecture/managers/test_exception_manager.py Tests exception stashing, consume-once read, and history retention behavior.
amber/src/main/python/core/architecture/managers/test_tuple_processing_manager.py Tests consume-once tuple/marker reads plus input-port-id fallback behavior.
amber/src/main/python/core/architecture/managers/test_statistics_manager.py Tests per-port aggregation, validation, processing-time accumulation, and idle-time behavior (incl. xfail probe).
amber/src/main/python/core/architecture/managers/test_console_message_manager.py Tests TimedBuffer-backed console message flushing behavior.
amber/src/main/python/core/architecture/managers/test_embedded_control_message_manager.py Tests ECM alignment modes, cleanup, and scope filtering behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread amber/src/main/python/core/architecture/managers/test_console_message_manager.py Outdated
…, fix _make_ecm comment

- test_get_without_flush_below_threshold_yields_nothing: pin
  `print_buf._last_output_time = datetime.now()` right before the
  assertion so the `>=1s` flush branch can't fire just because the
  rest of the test ran more than ~1s after construction.
- test_get_drains_when_last_output_time_is_stale: drop the unused
  `monkeypatch` parameter — the test backdates `_last_output_time`
  directly and never touches `datetime.now`.
- _make_ecm: replace the misleading "Reuse the same identity *object*
  across calls" comment with one that explains what actually happens —
  fresh EmbeddedControlMessageIdentity instances with id="ecm-1" hash
  equal under dataclass-style equality, so they aggregate under a
  single key in `ecm_received`.
@Yicong-Huang Yicong-Huang enabled auto-merge (squash) May 4, 2026 03:52
@aglinxinyuan aglinxinyuan disabled auto-merge May 4, 2026 04:05
@aglinxinyuan aglinxinyuan enabled auto-merge (squash) May 4, 2026 04:06
@aglinxinyuan aglinxinyuan merged commit 9f0cfd7 into apache:main May 4, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests for pyamber managers (state-processing, exception, console-message, tuple-processing, statistics, ECM)

4 participants