Skip to content

chore(test): bitswap limit tests - #7443

Merged
LesnyRumcajs merged 1 commit into
mainfrom
add-bitswap-tests
Aug 6, 2026
Merged

chore(test): bitswap limit tests#7443
LesnyRumcajs merged 1 commit into
mainfrom
add-bitswap-tests

Conversation

@LesnyRumcajs

@LesnyRumcajs LesnyRumcajs commented Aug 5, 2026

Copy link
Copy Markdown
Member

Summary of changes

Changes introduced in this pull request:

  • follow-up tests for fix: limit bitswap requests #7440, the coverage gain is small but it tests edge cases that wouldn't surface in the coverage report
  • moved the random cid helper so that it can be re-used in different test modules.

Reference issue to close (if applicable)

Closes

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Outside contributions

  • This pull request is based on an issue that a maintainer has accepted (see Before Opening a Pull Request).
  • I have read and agree to the CONTRIBUTING document.
  • I have read and agree to the AI Policy document. I understand that failure to comply with the guidelines will lead to rejection of the pull request.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of inbound wantlists by enforcing per-request entry limits.
    • Prevented excessive concurrent wantlist serving and correctly ignored empty wantlists.
  • Tests

    • Added coverage for wantlist limits, concurrency saturation, blocked reads, and response behavior.
    • Standardized test CID generation for more consistent test scenarios.

@LesnyRumcajs
LesnyRumcajs requested a review from a team as a code owner August 5, 2026 13:33
@LesnyRumcajs
LesnyRumcajs requested review from EclesioMeloJunior and akaladarshi and removed request for a team August 5, 2026 13:33
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The request manager exposes inbound serving limits within the Bitswap crate. New tests validate wantlist size limits, concurrency saturation, permit retention, and empty wantlists. Manifest tests now use a shared random CID helper.

Changes

Bitswap serving limits

Layer / File(s) Summary
Serving limit visibility
src/libp2p_bitswap/request_manager.rs, src/libp2p_bitswap/tests/request_manager.rs
The request manager exposes the maximum wantlist size and concurrent inbound serve count within the Bitswap crate. Tests import these limits.
Serving behavior validation
src/libp2p_bitswap/tests/request_manager.rs
Tests verify response limits, blocked reads, dropped serves when concurrency is saturated, and empty wantlist handling.
Shared random CID test support
src/utils/rand/mod.rs, src/shim/machine/manifest.rs
A test-only random CID helper is added. Manifest tests use the shared helper instead of local CID generation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • ChainSafe/forest#7440: Introduces the same inbound Bitswap wantlist-serving limits that this PR exposes and tests.

Suggested reviewers: akaladarshi, eclesiomelojunior, hanabi1224

🚥 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 identifies the main change: adding Bitswap limit tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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 add-bitswap-tests
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch add-bitswap-tests

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

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

🧹 Nitpick comments (1)
src/libp2p_bitswap/tests/request_manager.rs (1)

123-144: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Make the saturation test independent of the Tokio runtime blocking-thread limit by using a small test-local capacity.

The test depends on each of the first cap spawn_blocking tasks executing and blocking in GatedStore::contains() while holding permits. If FOREST_MAX_CONCURRENT_INBOUND_WANTLIST_SERVES is set above the runtime's blocking-thread limit (default 512), excess tasks remain queued and cannot signal entered_rx. The loop at line 139 then times out. Use a test-local constant for the cap (e.g., 4) instead of reading the global variable, or explicitly configure the test runtime to guarantee sufficient blocking capacity:

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn serve_drops_when_concurrency_saturated() {
    let cap = 4; // test-local, independent of global config
    // ... rest of test

This ensures the test remains deterministic regardless of how the global cap is set.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/libp2p_bitswap/tests/request_manager.rs` around lines 123 - 144, Update
the saturation test around serve_drops_when_concurrency_saturated to use a small
test-local capacity, such as 4, instead of dereferencing
MAX_CONCURRENT_INBOUND_WANTLIST_SERVES. Keep the existing saturation and
entered_rx synchronization logic unchanged so the test remains deterministic
regardless of the configured global limit.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/libp2p_bitswap/tests/request_manager.rs`:
- Around line 123-144: Update the saturation test around
serve_drops_when_concurrency_saturated to use a small test-local capacity, such
as 4, instead of dereferencing MAX_CONCURRENT_INBOUND_WANTLIST_SERVES. Keep the
existing saturation and entered_rx synchronization logic unchanged so the test
remains deterministic regardless of the configured global limit.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b3c7a370-5b42-42c7-b6fd-addd11073473

📥 Commits

Reviewing files that changed from the base of the PR and between a188092 and 25d02ef.

📒 Files selected for processing (4)
  • src/libp2p_bitswap/request_manager.rs
  • src/libp2p_bitswap/tests/request_manager.rs
  • src/shim/machine/manifest.rs
  • src/utils/rand/mod.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • filecoin-project/lotus (manual)

@LesnyRumcajs
LesnyRumcajs added this pull request to the merge queue Aug 6, 2026
Merged via the queue into main with commit dcef647 Aug 6, 2026
34 checks passed
@LesnyRumcajs
LesnyRumcajs deleted the add-bitswap-tests branch August 6, 2026 10:13
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