fix(test): avoid DNS discovery hang in SPV lifecycle tests#784
fix(test): avoid DNS discovery hang in SPV lifecycle tests#784
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughUpdated test helpers and assertions in the SPV test module to establish local node usage as the default behavior for test instances, changing peer-discovery initialization and aligning dependent test expectations accordingly. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
This PR updates the SPV lifecycle test harness to avoid DNS seed discovery during tests (which can hang due to an upstream startup cancellation issue), by forcing tests to use an explicit localhost peer instead.
Changes:
- Set
use_local_node(true)increate_test_manager()so SPV tests don’t trigger DNS seed discovery. - Update
test_use_local_node_toggleassertions to reflect the helper’s new default.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/spv/tests.rs (1)
156-161: Consider adding a test for the defaultuse_local_nodevalue.The updated assertions correctly reflect the helper's new behavior. However, this test no longer verifies that
SpvManager::new()initializesuse_local_nodetofalseby default — that behavior is now masked by the helper.Since the live testnet test (which creates
SpvManagerdirectly) is marked#[ignore], you may want to add a small test that constructsSpvManagerwithout the helper and asserts the default isfalse, ensuring the default initialization remains correct.💡 Optional: Add default value test
/// Given a freshly constructed SpvManager (not via helper), /// Then use_local_node defaults to false. #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn test_use_local_node_default_is_false() { let config = Arc::new(RwLock::new(test_network_config())); let task_manager = Arc::new(TaskManager::new()); let tmp_dir = tempfile::TempDir::new().expect("Failed to create temp dir"); let manager = SpvManager::new( tmp_dir.path(), Network::Testnet, config, task_manager, ) .expect("SpvManager::new should succeed"); assert!( !manager.use_local_node(), "Default use_local_node should be false" ); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/spv/tests.rs` around lines 156 - 161, The test currently exercises use_local_node via the test helper which masks SpvManager's default; add a focused unit test that constructs SpvManager directly (calling SpvManager::new with a temp dir, Network::Testnet, test_network_config wrapped in Arc<RwLock>, and a TaskManager) and then asserts that manager.use_local_node() is false to ensure the default initialization remains false; locate the new test near existing tests in src/spv/tests.rs and name it clearly (e.g., test_use_local_node_default_is_false).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/spv/tests.rs`:
- Around line 156-161: The test currently exercises use_local_node via the test
helper which masks SpvManager's default; add a focused unit test that constructs
SpvManager directly (calling SpvManager::new with a temp dir, Network::Testnet,
test_network_config wrapped in Arc<RwLock>, and a TaskManager) and then asserts
that manager.use_local_node() is false to ensure the default initialization
remains false; locate the new test near existing tests in src/spv/tests.rs and
name it clearly (e.g., test_use_local_node_default_is_false).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: efd55dda-4985-45e7-942f-0d7ef66509ed
📒 Files selected for processing (1)
src/spv/tests.rs
Summary
use_local_node(true)in the SPV test helpercreate_test_manager()so all lifecycle tests use the explicit localhost peer address (127.0.0.1:19999) instead of DNS seed discoverydash-spvlibrary, which hangs becauseDashSpvClient::run()doesn't check the cancellation token during its startup phase (upstream bug: dashpay/rust-dashcore#577)test_start_stop_clean_shutdownnow completes in ~0.3s instead of timing out at 10sUser story
Imagine you are a developer running
cargo teston the project. Previously,test_start_stop_clean_shutdownwould hang for 10 seconds and then fail — every time. Now all 20 SPV tests pass in ~1.4 seconds.Test plan
cargo test --all-features spv::tests::— all 20 tests pass (1.37s)test_start_stop_clean_shutdown— previously timed out, now passes in ~0.3stest_use_local_node_toggle— updated assertions match new default from test helper🤖 Co-authored by Claudius the Magnificent AI Agent
Summary by CodeRabbit