From 909aed91184fcfe8cccffb481a66515819242521 Mon Sep 17 00:00:00 2001 From: xyzconstant <263061129+xyzconstant@users.noreply.github.com> Date: Sat, 26 Sep 2026 13:49:30 -0300 Subject: [PATCH 1/2] test: drop interrupt call with nothing to interrupt `mining_check_block_and_interrupt` calls interrupt() while nothing is waiting, so it only checks that the call doesn't fail. Rename it to `mining_check_block`. --- tests/test.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/tests/test.rs b/tests/test.rs index 81ef141..1dd3f06 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -627,11 +627,10 @@ async fn mining_get_transactions() { .await; } -/// checkBlock with a template block payload, and interrupt. +/// checkBlock with a template block payload. #[tokio::test] -// Serialized because interrupt() can affect other in-flight mining waits. -#[serial_test::serial] -async fn mining_check_block_and_interrupt() { +#[serial_test::parallel] +async fn mining_check_block() { with_mining_client(|_client, mining| async move { let template = make_block_template(&mining).await; @@ -663,14 +662,6 @@ async fn mining_check_block_and_interrupt() { } destroy_template(&template).await; - - // interrupt — should not crash. - mining - .interrupt_request() - .send() - .promise - .await - .expect("interrupt should not fail"); }) .await; } From f3f1f8f0c762490be8f2303bc66940df4055ba0e Mon Sep 17 00:00:00 2001 From: xyzconstant <263061129+xyzconstant@users.noreply.github.com> Date: Sat, 26 Sep 2026 14:19:04 -0300 Subject: [PATCH 2/2] test: exercise interrupt methods Call `waitTipChanged` and `waitNext` with no timeout, let them block in a local task, then check that `interrupt` and `interruptWait` unblock them. --- tests/test.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/tests/test.rs b/tests/test.rs index 1dd3f06..0f354a7 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -5,6 +5,7 @@ use bitcoin_capnp_types::{ }; use capnp_rpc::{RpcSystem, rpc_twoparty_capnp::Side}; use encoding::encode_to_vec; +use std::time::Duration; use tokio::task::LocalSet; mod util; @@ -242,6 +243,32 @@ async fn mining_wait_tip_changed() { let wait_result = resp.get().unwrap().get_result().unwrap(); assert_eq!(wait_result.get_hash().unwrap().len(), 32); assert_eq!(wait_result.get_height(), tip_height); + + // No timeout. Pin a local task on the wait, then interrupt it. + let mut req = mining.wait_tip_changed_request(); + req.get().set_current_tip(&tip_hash); + let waiter = tokio::task::spawn_local(req.send().promise); + + // Give the waiter time to block before interrupting. + tokio::time::sleep(Duration::from_millis(100)).await; + assert!( + !waiter.is_finished(), + "waitTipChanged returned before interrupt" + ); + mining + .interrupt_request() + .send() + .promise + .await + .expect("interrupt should not fail"); + + let joined = tokio::time::timeout(Duration::from_secs(10), waiter) + .await + .expect("interrupt should unblock waitTipChanged"); + assert!( + joined.is_ok_and(|resp| resp.is_ok()), + "interrupted waitTipChanged should return normally" + ); }) .await; } @@ -333,7 +360,7 @@ async fn mining_block_template_inspection() { .await; } -/// waitNext (short timeout), interruptWait, submitSolution (garbage), destroy. +/// waitNext (short timeout), waitNext interrupted by interruptWait, submitSolution (garbage), destroy. #[tokio::test] // Serialized because submitSolution behavior depends on current chain tip. #[serial_test::serial] @@ -355,7 +382,19 @@ async fn mining_block_template_lifecycle() { "waitNext should time out without a new template" ); - // interruptWait — should not crash. + // waitNext — no timeout. Pin a local task on the wait, then interrupt it. + let mut req = template.wait_next_request(); + req.get() + .init_options() + .set_fee_threshold(mining_capnp::MAX_MONEY); + let waiter = tokio::task::spawn_local(req.send().promise); + + // Give the waiter time to block before interrupting. + tokio::time::sleep(Duration::from_millis(100)).await; + assert!( + !waiter.is_finished(), + "waitNext returned before interruptWait" + ); template .interrupt_wait_request() .send() @@ -363,6 +402,14 @@ async fn mining_block_template_lifecycle() { .await .expect("interruptWait should not fail"); + let joined = tokio::time::timeout(Duration::from_secs(10), waiter) + .await + .expect("interrupWait should unblock waitNext"); + assert!( + joined.is_ok_and(|resp| resp.is_ok()), + "interrupted waitNext should return normally" + ); + // submitSolution — garbage coinbase should be rejected. // This mutates the template, so we do it right before destroy. let mut req = template.submit_solution_request();