Skip to content

fix(tests): mark profiler timing tests with @allow_sleep (follow-up #1580)#1581

Merged
MervinPraison merged 2 commits into
mainfrom
fix/profiler-allow-sleep-marker
Apr 30, 2026
Merged

fix(tests): mark profiler timing tests with @allow_sleep (follow-up #1580)#1581
MervinPraison merged 2 commits into
mainfrom
fix/profiler-allow-sleep-marker

Conversation

@MervinPraison

@MervinPraison MervinPraison commented Apr 29, 2026

Copy link
Copy Markdown
Owner

Why

The merged version of #1580 tightened the profiler-test bounds from > 0 to >= 5 ms during review, but failed to opt out of conftest's autouse fast_sleep fixture (tests/conftest.py:183) which clamps time.sleep to 1ms for unit tests.

Result on main:

test_api_call_context_manager:  AssertionError: assert 1.1379... >= 5
test_streaming_tracker:         AssertionError: assert 1.2635... >= 5

Fix

Add @pytest.mark.allow_sleep to both timing-sensitive tests \u2014 the documented opt-out from the fast_sleep clamp. The 50ms sleep then runs for real and the >= 5ms assertion becomes meaningful.

Verification

PYTHONPATH=src/praisonai-agents:src/praisonai pytest \
  src/praisonai/tests/unit/test_profiler_advanced.py::TestAPICallProfiler::test_api_call_context_manager \
  src/praisonai/tests/unit/test_profiler_advanced.py::TestStreamingProfiler::test_streaming_tracker
# 2 passed

Combined with sandbox + ag2 + push_client suites: 12 passed, 2 skipped, 0 failed.

Risk

Test-only diff. No runtime behavior changes.

Summary by CodeRabbit

  • Tests
    • Marked timing-sensitive profiling tests to use real wall-clock sleeps so durations reflect true elapsed time during CI.
    • Clarified test documentation and timing rationale (CI sleep precision ~5ms) to explain lower-bound choices for duration and TTFT assertions.

…1580)

The merged version of PR #1580 tightened the profiler-test bounds from
'> 0' to '>= 5' ms, but failed to opt out of conftest's autouse
'fast_sleep' fixture (tests/conftest.py:183) which clamps time.sleep
to 1ms. Result: test_api_call_context_manager and test_streaming_tracker
fail with ~1.1ms duration on every run.

Add the documented opt-out marker (@pytest.mark.allow_sleep) so the
tests get a real 50ms sleep and the >= 5ms assertion is meaningful.

Verified locally: all 12 sandbox + profiler tests pass.
Copilot AI review requested due to automatic review settings April 29, 2026 06:02
@coderabbitai

coderabbitai Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2fbbac48-6ea6-4d28-98b4-ffef369396bb

📥 Commits

Reviewing files that changed from the base of the PR and between 1f6c3a7 and 31b90bd.

📒 Files selected for processing (1)
  • src/praisonai/tests/unit/test_profiler_advanced.py

📝 Walkthrough

Walkthrough

Adds @pytest.mark.allow_sleep to two timing-sensitive tests in test_profiler_advanced.py so they use real wall-clock time.sleep; updates docstring and inline comment to note CI-dependent sleep precision (~5ms). Assertions and measured lower bounds remain unchanged.

Changes

Cohort / File(s) Summary
Test Timing Configuration
src/praisonai/tests/unit/test_profiler_advanced.py
Added @pytest.mark.allow_sleep to two timing-sensitive tests to bypass the fast_sleep fixture; updated test docstring and time.sleep comment to reference CI timing precision (~5ms). Assertion logic unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

🐰 I paused my hop to count the beats,
Real seconds now on CI streets,
No clamp nor haste, the clocks align,
Tests hum true in honest time. 🕰️

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding @allow_sleep markers to profiler timing tests as a follow-up fix, making it directly related to the primary changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/profiler-allow-sleep-marker

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@MervinPraison

Copy link
Copy Markdown
Owner Author

@copilot Do a thorough review of this PR. Read ALL existing reviewer comments above from Qodo, Coderabbit, and Gemini first — incorporate their findings.

Review areas:

  1. Bloat check: Are changes minimal and focused? Any unnecessary code or scope creep?
  2. Security: Any hardcoded secrets, unsafe eval/exec, missing input validation?
  3. Performance: Any module-level heavy imports? Hot-path regressions?
  4. Tests: Are tests included? Do they cover the changes adequately?
  5. Backward compat: Any public API changes without deprecation?
  6. Code quality: DRY violations, naming conventions, error handling?
  7. Address reviewer feedback: If Qodo, Coderabbit, or Gemini flagged valid issues, include them in your review
  8. Suggest specific improvements with code examples where possible

@greptile-apps

greptile-apps Bot commented Apr 29, 2026

Copy link
Copy Markdown

Greptile Summary

Adds @pytest.mark.allow_sleep to two timing-sensitive profiler tests so they opt out of the autouse fast_sleep fixture (which clamps time.sleep to 1 ms) and let the real 50 ms sleep run, making the >= 5 ms wall-clock assertions meaningful. The marker is already registered in pytest.ini and recognised by conftest.py; the fix is a test-only change with no runtime impact.

Confidence Score: 5/5

Test-only change; safe to merge immediately.

The change is minimal and correct: the allow_sleep marker is already registered in pytest.ini and handled by conftest.py, no production code is touched, and the fix directly addresses the CI failures introduced by #1580.

No files require special attention.

Important Files Changed

Filename Overview
src/praisonai/tests/unit/test_profiler_advanced.py Adds @pytest.mark.allow_sleep to test_api_call_context_manager and test_streaming_tracker so the fast_sleep fixture is bypassed and real-duration assertions pass correctly.

Sequence Diagram

sequenceDiagram
    participant pytest
    participant conftest as conftest.py (fast_sleep)
    participant test as test_profiler_advanced.py
    participant sleep as time.sleep

    Note over pytest,sleep: Before fix — fast_sleep clamps sleep to 1ms
    pytest->>conftest: autouse fast_sleep fixture
    conftest->>sleep: monkeypatch → 0.001s max
    test->>sleep: time.sleep(0.05)
    sleep-->>test: returns after ~1ms
    test->>test: assert duration_ms >= 5 ❌ (~1ms)

    Note over pytest,sleep: After fix — @allow_sleep opts out
    pytest->>conftest: autouse fast_sleep fixture
    conftest->>conftest: sees allow_sleep marker → return early
    test->>sleep: time.sleep(0.05)
    sleep-->>test: returns after ~50ms
    test->>test: assert duration_ms >= 5 ✅ (~50ms)
Loading

Reviews (2): Last reviewed commit: "refactor(tests): move allow_sleep explan..." | Re-trigger Greptile

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds the @pytest.mark.allow_sleep decorator to the test_api_call_context_manager and test_streaming_tracker unit tests in test_profiler_advanced.py. This allows the tests to bypass the fast_sleep fixture and measure actual wall-clock duration. The review feedback suggests moving the inline comments explaining these changes into the test docstrings to better adhere to PEP 257 documentation standards.

Comment on lines +59 to +61
# ``allow_sleep`` opts out of the conftest ``fast_sleep`` fixture which
# otherwise clamps ``time.sleep`` to 1ms — needed here because the test
# asserts a real wall-clock duration was measured.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This is a helpful comment explaining the need for @pytest.mark.allow_sleep. For better documentation and adherence to Python's style guides, this explanation should be moved into the test's docstring. This makes the purpose of the test and its requirements clearer to anyone reading the docstring.

For example:

    def test_api_call_context_manager(self):
        """Should profile API call with context manager.

        The ``@allow_sleep`` marker opts out of the conftest ``fast_sleep`` fixture which
        otherwise clamps ``time.sleep`` to 1ms. This is needed here because the test
        asserts a real wall-clock duration was measured.
        """
References
  1. According to PEP 257, docstrings should contain explanations of a function's purpose and behavior. This comment would be better placed inside the function's docstring. (link)

Comment on lines +134 to +135
# ``allow_sleep`` opts out of conftest ``fast_sleep`` clamping so the
# TTFT measurement reflects real elapsed time.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the other test, this explanatory comment is valuable but would be more appropriately located within the test's docstring for better discoverability and consistency.

For example:

    def test_streaming_tracker(self):
        """Should track streaming with context manager.

        The ``@allow_sleep`` marker opts out of conftest ``fast_sleep`` clamping so the
        TTFT measurement reflects real elapsed time.
        """
References
  1. According to PEP 257, docstrings should contain explanations of a function's purpose and behavior. This comment would be better placed inside the function's docstring. (link)

@MervinPraison

Copy link
Copy Markdown
Owner Author

@claude You are the FINAL architecture reviewer. If the branch is under MervinPraison/PraisonAI (not a fork), you are able to make modifications to this branch and push directly. SCOPE: Focus ONLY on Python packages (praisonaiagents, praisonai). Do NOT modify praisonai-rust or praisonai-ts. Read ALL comments above from Gemini, Qodo, CodeRabbit, and Copilot carefully before responding.

Phase 1: Review per AGENTS.md

  1. Protocol-driven: check heavy implementations vs core SDK
  2. Backward compatible: ensure zero feature regressions
  3. Performance: no hot-path regressions

Phase 2: FIX Valid Issues
4. For any VALID bugs or architectural flaws found by Gemini, CodeRabbit, Qodo, Copilot, or any other reviewer: implement the fix
5. Push all code fixes directly to THIS branch (do NOT create a new PR)
6. Comment a summary of exact files modified and what you skipped

Phase 3: Final Verdict
7. If all issues are resolved, approve the PR / close the Issue
8. If blocking issues remain, request changes / leave clear action items

@praisonai-triage-agent

praisonai-triage-agent Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Claude finished @MervinPraison's task —— View job


Final Architecture Review ✅

Todo List:

  • Read AGENTS.md for architecture guidelines
  • Review the changed test file in detail
  • Address Gemini's feedback about moving comments to docstrings
  • Test the changes
  • Push any fixes to the branch
  • Provide final verdict

Scope: Python packages only (praisonaiagents, praisonai) - no Rust/TypeScript modifications.

Phase 1: Architecture Review per AGENTS.md

✅ Protocol-driven: This is a test-only change - no core SDK modifications.

✅ Backward compatible: Zero feature regressions - only fixes failing tests by allowing real time.sleep().

✅ Performance: No hot-path impact - test execution only.

Phase 2: Issues Fixed

✅ Addressed Gemini's feedback: Moved inline comments explaining @pytest.mark.allow_sleep to test docstrings per PEP 257 standards.

Files Modified:

  • src/praisonai/tests/unit/test_profiler_advanced.py - Improved docstring documentation

Commit: 31b90bd8 - refactor(tests): move allow_sleep explanations to docstrings

Phase 3: Final Verdict

✅ APPROVED - This PR is ready to merge.

Summary:

  • Correctly fixes failing timing tests by using documented @pytest.mark.allow_sleep opt-out
  • Follows PraisonAI architecture guidelines (test-only, no core changes)
  • Addresses all valid reviewer feedback
  • Clean, focused solution with no scope creep
  • Maintains test reliability while enabling real wall-clock timing validation

Risk Assessment: Minimal - test infrastructure improvement only, no runtime behavior changes.


| Branch: fix/profiler-allow-sleep-marker

Per Gemini code review feedback, moved inline comments explaining the
@pytest.mark.allow_sleep marker into test docstrings for better PEP 257
compliance. The marker opts out of conftest fast_sleep fixture clamping.

Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@MervinPraison MervinPraison merged commit 392a708 into main Apr 30, 2026
3 checks passed
@MervinPraison MervinPraison deleted the fix/profiler-allow-sleep-marker branch June 12, 2026 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants