Skip to content

Added assertions for request and response counts. #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2025

Conversation

AlexSkrypnyk
Copy link
Member

@AlexSkrypnyk AlexSkrypnyk commented Apr 5, 2025

Summary by CodeRabbit

  • Tests
    • Enhanced tests to verify the API server handles the expected number of requests and manages response queues accurately.
    • Updated scenarios ensure the server processes operations consistently, contributing to overall system robustness.

Copy link

coderabbitai bot commented Apr 5, 2025

Walkthrough

The changes add new assertions to verify the API server's state. Two public methods are introduced in the API server context class to check the number of queued responses and received requests by querying the /admin/status endpoint. The feature tests and documentation are also updated to assert that the API server receives the expected number of requests and has the correct response queue status.

Changes

File(s) Change Summary
README.md Added a summary section detailing the new assertions for verifying the API server’s request and response counts.
src/DrevOps/BehatPhpServer/ApiServerContext.php Introduced two public methods (assertQueuedResponsesCount and assertReceivedRequestsCount) that send a GET request to /admin/status and validate header values.
tests/behat/features/apiserver.feature Updated feature scenarios to include assertions that check the API server’s received request count (e.g., 3, 2) and that it maintains 0 queued responses.

Sequence Diagram(s)

sequenceDiagram
    participant T as Test Scenario
    participant C as ApiServerContext
    participant S as API Server (/admin/status)

    T->>C: Invoke assertQueuedResponsesCount / assertReceivedRequestsCount
    C->>S: GET /admin/status
    S-->>C: Return headers (X-Queued-Responses, X-Received-Requests)
    C-->>T: Log debug message or throw error on mismatch
Loading

Possibly related PRs

  • Added assertions from file. #37: This PR also involves modifications to the ApiServerContext class, focusing on adding methods for handling API responses and resetting the server, thereby complementing the new assertions introduced in this change.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@Copilot 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.

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

Files not reviewed (2)
  • src/DrevOps/BehatPhpServer/ApiServerContext.php: Language not supported
  • tests/behat/features/apiserver.feature: Language not supported

Copy link

codecov bot commented Apr 5, 2025

Codecov Report

Attention: Patch coverage is 44.44444% with 10 lines in your changes missing coverage. Please review.

Project coverage is 73.57%. Comparing base (4157252) to head (8ea1156).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/DrevOps/BehatPhpServer/ApiServerContext.php 44.44% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #38      +/-   ##
==========================================
- Coverage   74.87%   73.57%   -1.31%     
==========================================
  Files           3        3              
  Lines         402      420      +18     
==========================================
+ Hits          301      309       +8     
- Misses        101      111      +10     

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/DrevOps/BehatPhpServer/ApiServerContext.php (1)

369-391: Implementation of received requests assertion looks good.

The method correctly retrieves the API server status and compares the received requests count against the expected value, throwing an appropriate exception if they don't match. The implementation follows the same pattern as other assertion methods.

Consider type casting the count parameters and header values to integers before comparison for more robust numeric comparison:

-  if ($received_requests !== $count) {
+  if ((int)$received_requests !== (int)$count) {

This would ensure that string representations like "02" and "2" would be treated as equal.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 383-387: src/DrevOps/BehatPhpServer/ApiServerContext.php#L383-L387
Added lines #L383 - L387 were not covered by tests

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4157252 and 8ea1156.

📒 Files selected for processing (3)
  • README.md (2 hunks)
  • src/DrevOps/BehatPhpServer/ApiServerContext.php (1 hunks)
  • tests/behat/features/apiserver.feature (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
src/DrevOps/BehatPhpServer/ApiServerContext.php (1)
src/DrevOps/BehatPhpServer/PhpServerContext.php (1)
  • debug (625-633)
🪛 GitHub Check: codecov/patch
src/DrevOps/BehatPhpServer/ApiServerContext.php

[warning] 359-363: src/DrevOps/BehatPhpServer/ApiServerContext.php#L359-L363
Added lines #L359 - L363 were not covered by tests


[warning] 383-387: src/DrevOps/BehatPhpServer/ApiServerContext.php#L383-L387
Added lines #L383 - L387 were not covered by tests

🔇 Additional comments (4)
README.md (1)

157-162: Documentation looks good for the new assertion steps.

The added step definitions clearly document the new functionality for asserting the API server's state regarding requests and responses. This will be helpful for users who need to verify that their test scenarios are correctly interacting with the API server.

tests/behat/features/apiserver.feature (2)

148-149: Good addition of assertions to verify server state.

These assertions meaningfully extend the test coverage by validating both that the API server has received exactly the expected number of requests (3) and has emptied its response queue (0), which helps ensure the test scenario has run correctly.


189-190: Assertions correctly verify API server state after JSON responses.

The newly added assertions properly verify the server state after the test operations, confirming that exactly 2 requests were received and no responses remain in the queue.

src/DrevOps/BehatPhpServer/ApiServerContext.php (1)

345-367:

✅ Verification successful

Implementation of queued responses assertion looks good.

The method correctly retrieves the API server status and compares the queued responses count against the expected value, throwing an appropriate exception if they don't match. The implementation is consistent with the rest of the codebase.


🏁 Script executed:

#!/bin/bash
# Check test coverage for the new exception code paths

# Look for any existing tests that might purposely trigger the exception case
rg -A 3 -B 3 "should have \d+ (queued|response)" tests/

Length of output: 1207


Queued Responses Assertion Implementation Verified

The implementation in src/DrevOps/BehatPhpServer/ApiServerContext.php (lines 345–367) correctly retrieves the API server's status and validates the queued responses count. The test outputs confirm that both the "queued responses" and "responses queued" assertions are being exercised in the feature tests. No further changes are necessary.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 359-363: src/DrevOps/BehatPhpServer/ApiServerContext.php#L359-L363
Added lines #L359 - L363 were not covered by tests

@AlexSkrypnyk AlexSkrypnyk merged commit 7398809 into main Apr 5, 2025
5 of 7 checks passed
@AlexSkrypnyk AlexSkrypnyk deleted the fixture/count-assertions branch April 5, 2025 05:00
@AlexSkrypnyk AlexSkrypnyk mentioned this pull request Apr 5, 2025
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.

1 participant