Skip to content

Conversation

fm3
Copy link
Member

@fm3 fm3 commented Apr 14, 2025

  • Adds some unit test for the NativeBucketScanner class
  • Also test that it can be instantiated in datastore healthcheck (but only once)

Steps to test:

  • Datastore health check should be green
  • Adapt the expected value in the check in Application.scala, re-visit data/health, should give readable error message.

Issues


@fm3 fm3 self-assigned this Apr 14, 2025
Copy link
Contributor

coderabbitai bot commented Apr 14, 2025

📝 Walkthrough

"""

Walkthrough

This change introduces a comprehensive test suite for the NativeBucketScanner class, verifying its core functionalities such as segment ID extraction, voxel counting, and bounding box extension using various byte array inputs. The health check endpoint in the application controller is also updated to include a runtime validation of the NativeBucketScanner, ensuring its correctness by comparing scanned segment IDs against expected results during startup. Additionally, the CI workflow modifies curl commands to use --fail-with-body for improved error output in smoke tests. These changes enhance the reliability and test coverage of the native scanning logic within the backend.

Changes

File(s) Change Summary
test/backend/BucketScannerTestSuite.scala Added a new test suite for NativeBucketScanner, covering segment ID collection (including skip-zero behavior), voxel counting, and bounding box extension.
webknossos-datastore/app/com/scalableminds/webknossos/datastore/controllers/Application.scala Enhanced the health check endpoint to include a runtime test of NativeBucketScanner correctness, throwing an error if validation fails.
.github/workflows/build_test_deploy.yml Updated curl commands in smoke tests to use --fail-with-body instead of --fail for better error reporting.

Assessment against linked issues

Objective Addressed Explanation
Add backend unit tests for NativeBucketScanner (#8526)

Possibly related PRs

Suggested reviewers

  • frcroth

Poem

In the warren where data hops and scans,
New tests now check the scanner’s plans.
Segments are counted, bounding boxes expand,
Health checks ensure all’s as we planned.
With every byte and bounding box true,
This rabbit says, “Well done, team—thank you!”
🐇✨
"""


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 44b6014 and 7458ec3.

📒 Files selected for processing (1)
  • .github/workflows/build_test_deploy.yml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/build_test_deploy.yml
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build-smoketest-push
  • GitHub Check: backend-tests

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
🪧 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 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.

@fm3 fm3 changed the title WIP Add unit tests for native bucket scanner Add unit tests for native bucket scanner, also check it in data/health Apr 15, 2025
@fm3 fm3 marked this pull request as ready for review April 15, 2025 11:23
@fm3 fm3 requested a review from frcroth April 15, 2025 11:23
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

🧹 Nitpick comments (3)
test/backend/BucketScannerTestSuite.scala (3)

33-49: Update comment to reflect all values in array

The test logic is good, but the comment on line 35 doesn't fully match the array contents.

- // little endian uint16 representation of 2, 4, 500, 500
+ // little endian uint16 representation of 2, 4, 500, 500, 0

The array includes an additional zero value at the end (bytes 8-9), which is correctly tested for in the assertions but not mentioned in the comment.


51-66: Good test coverage for voxel counting functionality

This test effectively verifies both positive and negative cases for segment voxel counting.

There's a minor discrepancy in the comment on line 53:

- // little endian uint16 representation of 2, 4, 500, 500
+ // little endian uint32 representation of 2, 4, 500, 500

The test is correctly using uint32, but the comment says uint16.


68-94: Add clarifying comments to the bounding box test

The bounding box test is well-implemented but fairly complex. Consider adding more explanatory comments to improve readability.

Specific areas that would benefit from additional comments:

  1. The calculation of bytesPerBucket (lines 70-73) - explain why you're calculating it this way
  2. The setting of specific bytes (lines 74-75) - explain what these positions represent in 3D space
  3. The meaning of the many parameters passed to extendSegmentBoundingBox (lines 77-92) - particularly the Int.Min/MaxValue parameters and what they represent

For example:

// Set segment ID 1 at positions that will result in a bounding box from (5,1,0) to (8,1,0)
array(ElementClass.bytesPerElement(elementClass) * (DataLayer.bucketLength + 5)) = 1
array(ElementClass.bytesPerElement(elementClass) * (DataLayer.bucketLength + 8)) = 1
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4cb908f and 914a965.

📒 Files selected for processing (2)
  • test/backend/BucketScannerTestSuite.scala (1 hunks)
  • webknossos-datastore/app/com/scalableminds/webknossos/datastore/controllers/Application.scala (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-test-e2e-deploy
🔇 Additional comments (4)
webknossos-datastore/app/com/scalableminds/webknossos/datastore/controllers/Application.scala (1)

5-9: Health endpoint integration looks good

The integration of the NativeBucketScanner test into the health endpoint is well implemented. Using the toFox ?~> pattern maintains consistency with the existing error handling approach in this method.

Also applies to: 29-29

test/backend/BucketScannerTestSuite.scala (3)

7-19: Well-structured test for uint16 segment ID collection

The test for collecting segment IDs from a uint16 byte array is well-structured and clearly demonstrates the expected functionality of the NativeBucketScanner.


21-31: Effective test for uint32 element class compatibility

Good test that verifies the scanner works correctly with uint32 values, demonstrating element class flexibility.


7-96: Comprehensive test coverage for NativeBucketScanner

The test suite provides excellent coverage of the NativeBucketScanner's functionality, including segment ID collection, zero-skipping, voxel counting, and bounding box calculations. The tests are well-structured, independent, and verify both positive and negative cases where appropriate.

This implementation aligns perfectly with the PR objective of adding unit tests for the NativeBucketScanner class. The tests complement the runtime verification added to the health check endpoint.

Copy link
Contributor

@frcroth frcroth left a comment

Choose a reason for hiding this comment

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

Nice 👍

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: 0

🧹 Nitpick comments (1)
.github/workflows/build_test_deploy.yml (1)

217-234: DRY up repeated smoke-test steps using a matrix
The three smoke-test steps differ only by URL. You can reduce duplication by leveraging a matrix strategy:

-      - name: Run webknossos smoke test
-        uses: ./.github/actions/retry
-        with:
-          run: curl -v --fail-with-body "http://localhost:9000/api/health"
-          retries: 20
-          retry_delay_seconds: 5
-      - name: Run webknossos-datastore smoke test
-        uses: ./.github/actions/retry
-        with:
-          run: curl -v --fail-with-body "http://localhost:9090/data/health"
-          retries: 20
-          retry_delay_seconds: 5
-      - name: Run webknossos-tracingstore smoke test
-        uses: ./.github/actions/retry
-        with:
-          run: curl -v --fail-with-body "http://localhost:9050/tracings/health"
-          retries: 20
-          retry_delay_seconds: 5
+      - name: Run service health smoke tests
+        uses: ./.github/actions/retry
+        strategy:
+          matrix:
+            service:
+              - {name: webknossos, url: "http://localhost:9000/api/health"}
+              - {name: datastore, url: "http://localhost:9090/data/health"}
+              - {name: tracingstore, url: "http://localhost:9050/tracings/health"}
+        with:
+          run: |
+            echo "Testing ${{ matrix.service.name }} at ${{ matrix.service.url }}"
+            curl -v --fail-with-body "${{ matrix.service.url }}"
+          retries: 20
+          retry_delay_seconds: 5

This will make it easier to add or remove services later without copying the same step multiple times.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4769db8 and 9ee9d8d.

📒 Files selected for processing (1)
  • .github/workflows/build_test_deploy.yml (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build-smoketest-push
  • GitHub Check: backend-tests
🔇 Additional comments (2)
.github/workflows/build_test_deploy.yml (2)

99-99: Upgrade CI runner to Ubuntu 24.04
Updating the build-smoketest-push job from ubuntu-22.04 to ubuntu-24.04 brings newer system libraries and security patches. Please verify that all required tools (Java 21, SBT, libdraco-dev, libblosc1, etc.) remain fully compatible in this environment before merging.


220-220: Switch to curl --fail-with-body for richer failure output
Replacing --fail with --fail-with-body will include the HTTP response body on failures, which is invaluable for diagnosing health‐check errors. Confirm that the default curl on Ubuntu 24.04 (requires ≥ 7.76) supports this flag so the smoke tests don’t break unexpectedly.

Also applies to: 226-226, 232-232

@fm3 fm3 enabled auto-merge (squash) April 22, 2025 07:57
@fm3 fm3 merged commit 0baa33e into master Apr 22, 2025
5 checks passed
@fm3 fm3 deleted the bucket-scanner-test-suite branch April 22, 2025 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unit tests for NativeBucketScanner

2 participants