Skip to content

chore: optimize slow net tests - #7363

Draft
cylewitruk-stacks wants to merge 6 commits into
stacks-network:mainfrom
cylewitruk-stacks:chore/slow-net-tests
Draft

chore: optimize slow net tests#7363
cylewitruk-stacks wants to merge 6 commits into
stacks-network:mainfrom
cylewitruk-stacks:chore/slow-net-tests

Conversation

@cylewitruk-stacks

Copy link
Copy Markdown
Contributor

This PR speeds up a set of slow networking tests by replacing artificial wall-clock waits with natural progressions and shrinking oversized fixtures, while preserving the production paths and assertions being exercised:

  • Added short-poll TestPeer helpers so tests can avoid repeated 100ms idle polls without changing default behavior.
  • Replaced sleep-based neighbor walk, heartbeat, bandwidth, and cleanup tests with direct timestamp aging/population.
  • Reduced paginated mempool fixtures to the minimum size that still exercises multi-page continuation.
  • Split update_highest_stacks_neighbor coverage into a fast pure-rule matrix plus one wrapper smoke test through StacksNodeState.
  • Removed unnecessary Nakamoto fixture setup from relay buffer/direct-handler tests.
  • Fixed with_timeout to use channel recv_timeout instead of a sleep/poll loop.

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

Pull request overview

This PR reduces runtime and flakiness in stackslib networking tests by replacing wall-clock sleeps/long polls with deterministic state aging and shorter poll timeouts, while preserving production code paths and assertions.

Changes:

  • Added TestPeer stepping helpers that accept a custom poll timeout, and updated many in-process net tests to use short polls.
  • Reworked multiple tests to advance internal timestamps/state directly (neighbor-walk, heartbeat, disconnect-unresponsive, bandwidth stats) instead of sleeping.
  • Reduced oversized fixtures (notably mempool pagination) and removed unnecessary Nakamoto fixture bootstrapping from tests that don’t need it; refactored update_highest_stacks_neighbor logic for more direct unit testing.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
stackslib/src/util_lib/mod.rs Updates with_timeout to use recv_timeout instead of a sleep/poll loop.
stackslib/src/net/tests/relay/nakamoto.rs Uses short-poll stepping in relay tests; removes unnecessary Nakamoto fixture setup in buffer/direct-handler tests.
stackslib/src/net/tests/neighbors.rs Introduces short-poll stepping helpers and deterministic timestamp aging to eliminate long sleeps.
stackslib/src/net/tests/mod.rs Splits update_highest_stacks_neighbor coverage into pure logic tests plus a node-state smoke test.
stackslib/src/net/tests/mempool/mod.rs Shrinks pagination fixture size and enforces pagination via a reduced mempool_max_tx_query; short-poll stepping.
stackslib/src/net/tests/inv/nakamoto.rs Shortens in-process peer stepping polls for inventory sync tests.
stackslib/src/net/tests/inv/epoch2x.rs Uses short-poll stepping in epoch2x inventory tests.
stackslib/src/net/tests/httpcore.rs Simplifies mock server teardown by closing immediately after responding (no client-done channel).
stackslib/src/net/tests/download/nakamoto.rs Uses short-poll stepping/run loops to speed download tests.
stackslib/src/net/server.rs Shortens polling and reduces connect-timeout waits in HTTP server tests.
stackslib/src/net/p2p.rs Removes long sleeps by directly aging connection timestamps in disconnect_unresponsive test.
stackslib/src/net/mod.rs Extracts update_highest_stacks_neighbor_value and adds TestPeer timeout-aware stepping APIs.
stackslib/src/net/chat.rs Replaces sleep-based bandwidth tests with deterministic timestamp population; consolidates repeated tests via a macro.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread stackslib/src/util_lib/mod.rs
@coveralls

coveralls commented Jun 30, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 28606722758

Coverage increased (+0.5%) to 86.216%

Details

  • Coverage increased (+0.5%) from the base build.
  • Patch coverage: 17 uncovered changes across 3 files (102 of 119 lines covered, 85.71%).
  • 9165 coverage regressions across 139 files.

Uncovered Changes

File Changed Covered %
stackslib/src/net/p2p.rs 26 18 69.23%
stackslib/src/net/mod.rs 52 47 90.38%
stackslib/src/util_lib/mod.rs 9 5 55.56%
Total (5 files) 119 102 85.71%

Coverage Regressions

9165 previously-covered lines in 139 files lost coverage.

Top 10 Files by Coverage Loss Lines Losing Coverage Coverage
stackslib/src/chainstate/stacks/db/blocks.rs 508 89.86%
stackslib/src/chainstate/burn/db/sortdb.rs 504 90.2%
stackslib/src/chainstate/nakamoto/mod.rs 432 84.87%
stackslib/src/net/mod.rs 319 77.93%
stackslib/src/config/mod.rs 292 77.47%
stackslib/src/chainstate/stacks/index/storage.rs 277 82.41%
clarity/src/vm/database/clarity_db.rs 268 82.11%
stackslib/src/chainstate/stacks/miner.rs 260 83.56%
stackslib/src/chainstate/stacks/db/transactions.rs 253 97.15%
stackslib/src/net/inv/epoch2x.rs 222 79.44%

Coverage Stats

Coverage Status
Relevant Lines: 226495
Covered Lines: 195274
Line Coverage: 86.22%
Coverage Strength: 19675888.56 hits per line

💛 - Coveralls

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.

3 participants