Skip to content
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

test(core): Update network_reader_with_valid_http_header_kv_pairs to verify the return value before parsing the read content into a JSON object. #593

Merged
merged 2 commits into from
Nov 15, 2024

Conversation

LinZhihao-723
Copy link
Member

@LinZhihao-723 LinZhihao-723 commented Nov 15, 2024

Description

We've seen network_reader_with_valid_http_header_kv_pairs test failures in recent macOS workflow runs. These runs can be normally resolved by rerunning the workflow jobs. After further investigation, we realized the requested URL returned an error code 502. This is not our fault; however, the current unit test won't give us a straightforward error message. This PR improves error reporting by reordering the test code to check CURL return code before parsing the read content into a JSON object.

The error message before this PR on failure:

-------------------------------------------------------------------------------
network_reader_with_valid_http_header_kv_pairs
-------------------------------------------------------------------------------
/Users/lzh/clp/components/core/tests/test-NetworkReader.cpp:195
...............................................................................

/Users/lzh/clp/components/core/tests/test-NetworkReader.cpp:195: FAILED:
  {Unknown expression after the reported line}
due to unexpected exception with message:
  [json.exception.parse_error.101] parse error at line 1, column 1: attempting
  to parse an empty input; check that your input string or stream contains the
  expected JSON

The error message after this PR:

-------------------------------------------------------------------------------                                                                                                                                    
network_reader_with_valid_http_header_kv_pairs                                                                                                                                                                     
-------------------------------------------------------------------------------                                                                                                                                    
/Users/lzh/clp/components/core/tests/test-NetworkReader.cpp:195                                                                                                                                                    
...............................................................................                                                                                                                                    
                                                                                                                                                                                                                   
/Users/lzh/clp/components/core/tests/test-NetworkReader.cpp:100: warning:                                                                                                                                          
  Unexpected CURL error code: 56; expected: 0                                                                                                                                                                      
  Error message:                                                                                                                                                                                                   
  The requested URL returned error: 502                                                                                                                                                                            
                                                                                                                                                                                                                   
/Users/lzh/clp/components/core/tests/test-NetworkReader.cpp:218: FAILED:                                                                                                                                           
  REQUIRE( assert_curl_error_code(CURLE_OK, reader) )                                                                                                                                                              
with expansion:                                                                                                                                                                                                    
  false                   

After the fix, the error message should look more apparent, as if the error is not on our end.

Validation performed

  • Unit tests all passed locally
  • Ensure workflows are all passed

Summary by CodeRabbit

  • Tests
    • Improved clarity in the network_reader_with_valid_http_header_kv_pairs test case by renaming variables for better understanding.
    • Updated variable references in assertions to enhance readability without altering test logic.
    • Minor adjustments made to comments and formatting for improved consistency.

Copy link
Contributor

coderabbitai bot commented Nov 15, 2024

Walkthrough

The changes in this pull request involve modifications to the network_reader_with_valid_http_header_kv_pairs test case located in components/core/tests/test-NetworkReader.cpp. The variable content has been renamed to context for improved clarity, and subsequent references to this variable have been updated accordingly. The parsing of JSON content now uses context, with the result stored in parsed_content. Minor adjustments to comments and formatting were also made, but the overall structure and functionality of the tests remain unchanged.

Changes

File Change Summary
components/core/tests/test-NetworkReader.cpp Renamed variable content to context, updated JSON parsing to use context, and adjusted comments for clarity.

Possibly related PRs

  • core: Add support for user-defined HTTP headers in NetworkReader. #568: This PR modifies the NetworkReader class, which is directly related to the changes made in the main PR that updates the network_reader_with_valid_http_header_kv_pairs test case in the same class. The changes in both PRs focus on handling HTTP headers, indicating a strong connection at the code level.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 80f19f4 and 5bbe668.

📒 Files selected for processing (1)
  • components/core/tests/test-NetworkReader.cpp (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/core/tests/test-NetworkReader.cpp

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 resolve resolve all the CodeRabbit review comments.
  • @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
Contributor

@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: 1

🧹 Outside diff range and nitpick comments (2)
components/core/tests/test-NetworkReader.cpp (2)

216-216: Consider a more descriptive variable name

The variable name change from content to context might be confusing as the variable actually contains the HTTP response content, not a context.

-    auto const context{get_content(reader)};
+    auto const response_content{get_content(reader)};

216-219: Consider adding platform-specific error handling

Since the PR objectives mention failures in macOS workflow runs, consider adding platform-specific error handling similar to what's done in the network_reader_illegal_offset test case.

     auto const context{get_content(reader)};
-    REQUIRE(assert_curl_error_code(CURLE_OK, reader));
+    if constexpr (clp::Platform::MacOs == clp::cCurrentPlatform) {
+        // Handle potential 502 errors differently on macOS
+        if (!assert_curl_error_code(CURLE_OK, reader)) {
+            auto const ret_code = reader.get_curl_ret_code();
+            if (ret_code.has_value() && ret_code.value() == CURLE_GOT_NOTHING) {
+                FAIL(fmt::format(
+                    "MacOS-specific HTTP error: {}",
+                    reader.get_curl_error_msg().value_or("502 Bad Gateway")
+                ));
+            }
+        }
+    } else {
+        REQUIRE(assert_curl_error_code(CURLE_OK, reader));
+    }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 53c4f52 and 80f19f4.

📒 Files selected for processing (1)
  • components/core/tests/test-NetworkReader.cpp (1 hunks)

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