Skip to content

Reuse fixture in payload index test#6041

Merged
coszio merged 6 commits intodevfrom
reuse-fixture-in-payload-index-test
Feb 24, 2025
Merged

Reuse fixture in payload index test#6041
coszio merged 6 commits intodevfrom
reuse-fixture-in-payload-index-test

Conversation

@coszio
Copy link
Copy Markdown
Contributor

@coszio coszio commented Feb 24, 2025

This improves the execution speed of the module from around 20 secs down to 7.5 secs, at least with nextest. Command:

cargo nextest run  -p segment --test integration payload_index_test
  • Refactors to run all tests within a single one to reuse the fixture
  • Each test returns an anyhow::Result with an error stating the place of error, as what assert!() would do
  • Runs the tests in parallel
  • Reduces the amount of attempts for each test. And makes each attempt different in the case of geo filters (we were repeating the same request for 100 times 😱)

@coszio coszio added the chore Nice to have improvement label Feb 24, 2025
@coszio coszio requested a review from timvisee February 24, 2025 15:35
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 24, 2025

📝 Walkthrough

Walkthrough

The changes introduce a new development dependency (anyhow version 1.0.96) in the project’s Cargo configuration and refactor the integration tests in the segment module. The test suite modifications include replacing standard assertions with the ensure! macro for better error reporting, reducing iteration attempts, removing an unneeded helper function, and updating multiple test function signatures to accept a shared TestSegments parameter and return a Result type.

Changes

File(s) Change Summary
lib/segment/Cargo.toml Added anyhow = "1.0.96" to the [dev-dependencies] section.
lib/segment/tests/integration/payload_index_test.rs Updated error handling by replacing assertions with the ensure! macro; reduced ATTEMPTS from 100 to 20; removed the get_read_only_segments function; and modified multiple test function signatures to accept a &TestSegments parameter and return Result<()>.

Sequence Diagram(s)

sequenceDiagram
    participant TH as Test Harness
    participant TS as TestSegments
    participant TF as Test Function
    participant EH as Error Handler (anyhow/ensure!)

    TH->>TS: Initialize shared TestSegments
    TH->>TF: Call test_function(TestSegments)
    TF->>TF: Execute test logic with ensure! checks
    alt Failure Condition
        TF->>EH: Trigger ensure! error reporting
        EH-->>TF: Return error (Result::Err)
        TF-->>TH: Report test failure
    else Success Condition
        TF-->>TH: Return success (Result::Ok)
    end
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 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. (Beta)
  • @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
Copy Markdown
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: 0

🧹 Nitpick comments (1)
lib/segment/tests/integration/payload_index_test.rs (1)

449-522: Validate geo filter function logic.

The function systematically compares results from different segment types with ensure! checks. This looks correct for verifying consistent results and cardinalities.

For greater clarity when comparing floating-point scores, consider using an absolute difference:

- ensure!((r1.score - r2.score) < 0.0001)
+ ensure!((r1.score - r2.score).abs() < 0.0001)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 490660a and bcac73d.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • lib/segment/Cargo.toml (1 hunks)
  • lib/segment/tests/integration/payload_index_test.rs (24 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: test-snapshot-operations-s3-minio
  • GitHub Check: test-shard-snapshot-api-s3-minio
  • GitHub Check: test-low-resources
  • GitHub Check: test-consistency
  • GitHub Check: test-consensus-compose
  • GitHub Check: Basic TLS/HTTPS tests
  • GitHub Check: test (macos-latest)
  • GitHub Check: test-consensus
  • GitHub Check: test (windows-latest)
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: test (ubuntu-latest)
  • GitHub Check: test
🔇 Additional comments (15)
lib/segment/Cargo.toml (1)

39-39: New dev-dependency addition looks good.

Adding anyhow 1.0.96 for improved error management is a solid choice. Just ensure there are no new security advisories or compatibility issues with this version.

Feel free to run a quick vulnerability and changelog check to confirm everything is safe and stable.

lib/segment/tests/integration/payload_index_test.rs (14)

5-7: Imports for concurrency and error handling.

Introducing Arc for shared data in parallel tests and anyhow for improved error context is a good upgrade. No issues spotted.


525-555: Parallel read operations test.

Spawning threads to run multiple test functions in parallel is excellent for speed. Given the segments seem read-only here, no data-race issues are apparent. Well done.


557-610: IS_EMPTY conditions handling.

Using ensure! macros to verify cardinalities and result equality between segments is consistent. This approach aligns well with your broader error-handling strategy.


648-686: Cardinality estimation for integer range checks.

This test correctly compares the exact matched count against the estimated min/max. The logic for random-range filtering is well-structured.


811-929: Structured payload index test.

Comparing plain, struct, and mmap segments with the same queries ensures index consistency. The additional check on sorted results is a neat way to handle tie-breaking.


931-953: Geo bounding-box filter test.

Invoking validate_geo_filter with bounding-box data and chaining .context(here!())? provides clarity on errors. This approach is straightforward and effective.


955-975: Geo radius filter test.

Similarly using validate_geo_filter for radius-based checks is consistent. No issues found.


977-1015: Geo polygon filter test.

Leveraging validate_geo_filter for polygon-based filters, including interiors, is well-structured. The function’s geometry generation logic is clear.


1157-1207: Any matcher cardinality estimation.

The test ensures that primary clauses and cardinality estimates align correctly for multi-value string matches. This is a solid check with the ensure! macro.


1229-1256: Facet result validation.

The approach of verifying exact counts by re-checking each value is robust. ensure!(*count == exact) helps catch discrepancies effectively.


1258-1274: Keyword facet test in struct segment.

Ensuring the plain segment fails gracefully (no keyword index) and validating correct facet results in the struct segment is an excellent coverage step.


1276-1285: Mmap keyword facet test.

Parallel to the struct version, confirming keyword facet results on mmap segment is consistent. No concerns spotted.


1287-1303: Faceted keyword test with random filters in struct segment.

Looping multiple times with random filters ensures reliability. Good usage of here!() for diagnosing any test failures.


1305-1321: Faceted keyword test with random filters in mmap segment.

Identical approach to the struct segment ensures coverage. Valid usage of internal checks and consistent filtering logic.

@coszio coszio merged commit 8ec07b6 into dev Feb 24, 2025
@coszio coszio deleted the reuse-fixture-in-payload-index-test branch February 24, 2025 16:55
timvisee pushed a commit that referenced this pull request Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Nice to have improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants