Skip to content

Commit d51aa1c

Browse files
committed
test: delete StopSignal, call handle.stop() directly
StopSignal was a test-only actor message that only worked via the production-specific TokioRuntimeHandle::stop() it used under the hood. The `peer_recover` test is the sole caller; it already has the `TokioRuntimeHandle` from PeerManagerActor::spawn(), so it can call .stop() directly and skip the message round-trip. Production shutdown flows through actor_system.stop() and is unaffected. The unused `should_panic: true` variant goes too — it was never called outside its own constructor.
1 parent 7fbd404 commit d51aa1c

2 files changed

Lines changed: 7 additions & 28 deletions

File tree

chain/network/src/test_utils.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -111,30 +111,6 @@ impl Handler<GetInfo, crate::types::NetworkInfo> for PeerManagerActor {
111111
}
112112
}
113113

114-
// `StopSignal is used to stop PeerManagerActor for unit tests
115-
#[derive(Default, Debug)]
116-
pub struct StopSignal {
117-
pub should_panic: bool,
118-
}
119-
120-
impl StopSignal {
121-
pub fn should_panic() -> Self {
122-
Self { should_panic: true }
123-
}
124-
}
125-
126-
impl Handler<StopSignal> for PeerManagerActor {
127-
fn handle(&mut self, msg: StopSignal) {
128-
tracing::debug!(target: "network", "received stop signal");
129-
130-
if msg.should_panic {
131-
panic!("Node crashed");
132-
} else {
133-
self.transport.shutdown();
134-
}
135-
}
136-
}
137-
138114
// Mocked `PeerManager` adapter, has a queue of `PeerManagerMessageRequest` messages.
139115
#[derive(Default)]
140116
pub struct MockPeerManagerAdapter {

integration-tests/src/tests/network/peer_handshake.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::tests::network::runner::*;
2-
use near_async::messaging::{CanSend, CanSendAsync};
2+
use near_async::messaging::CanSendAsync;
33
use near_async::tokio::TokioRuntimeHandle;
44
use near_async::{ActorSystem, time};
55
use near_network::PeerManagerActor;
66
use near_network::config;
77
use near_network::tcp;
8-
use near_network::test_utils::{GetInfo, StopSignal, convert_boot_nodes, wait_or_timeout};
8+
use near_network::test_utils::{GetInfo, convert_boot_nodes, wait_or_timeout};
99
use near_o11y::testonly::init_test_logger;
1010
use near_primitives::genesis::GenesisId;
1111
use parking_lot::Mutex;
@@ -152,8 +152,11 @@ async fn peer_recover() {
152152
// Wait a small timeout for connection to be active.
153153
state.store(1, Ordering::Relaxed);
154154
} else if state.load(Ordering::Relaxed) == 1 {
155-
// Stop node2.
156-
let _ = pm2.lock().send(StopSignal::default());
155+
// Stop node2 by cancelling its tokio runtime. This triggers
156+
// `stop_actor` on drop (broadcasts Disconnect, shuts down
157+
// transport) and cancels all spawned tasks (PeerActors,
158+
// background loops), closing the TCP connections to peers.
159+
pm2.lock().stop();
157160
state.store(2, Ordering::Relaxed);
158161
} else if state.load(Ordering::Relaxed) == 2 {
159162
// Wait until node0 removes node2 from active validators.

0 commit comments

Comments
 (0)