Skip to content

Commit

Permalink
Dedup runtime shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Jul 5, 2023
1 parent 92650ca commit 1f9a7a0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 23 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 2 additions & 12 deletions beacon_node/http_api/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use std::sync::Arc;
use std::time::Duration;
use store::MemoryStore;
use task_executor::test_utils::TestRuntime;
use tokio::sync::{mpsc, oneshot};
use tokio::sync::mpsc;
use types::{ChainSpec, EthSpec};

pub const TCP_PORT: u16 = 42;
Expand All @@ -46,7 +46,6 @@ pub struct InteractiveTester<E: EthSpec> {
pub harness: BeaconChainHarness<EphemeralHarnessType<E>>,
pub client: BeaconNodeHttpClient,
pub network_rx: NetworkReceivers<E>,
_server_shutdown: oneshot::Sender<()>,
_test_runtime: TestRuntime,
}

Expand All @@ -56,7 +55,6 @@ pub struct InteractiveTester<E: EthSpec> {
pub struct ApiServer<E: EthSpec, SFut: Future<Output = ()>> {
pub server: SFut,
pub listening_socket: SocketAddr,
pub shutdown_tx: oneshot::Sender<()>,
pub network_rx: NetworkReceivers<E>,
pub local_enr: Enr,
pub external_peer_id: PeerId,
Expand Down Expand Up @@ -105,7 +103,6 @@ impl<E: EthSpec> InteractiveTester<E> {
let ApiServer {
server,
listening_socket,
shutdown_tx: _server_shutdown,
network_rx,
test_runtime,
..
Expand All @@ -127,7 +124,6 @@ impl<E: EthSpec> InteractiveTester<E> {
harness,
client,
network_rx,
_server_shutdown,
_test_runtime: test_runtime,
}
}
Expand Down Expand Up @@ -231,17 +227,11 @@ pub async fn create_api_server_on_port<T: BeaconChainTypes>(
log,
});

let (shutdown_tx, shutdown_rx) = oneshot::channel();
let server_shutdown = async {
// It's not really interesting why this triggered, just that it happened.
let _ = shutdown_rx.await;
};
let (listening_socket, server) = crate::serve(ctx, server_shutdown).unwrap();
let (listening_socket, server) = crate::serve(ctx, test_runtime.task_executor.exit()).unwrap();

ApiServer {
server,
listening_socket,
shutdown_tx,
network_rx: network_receivers,
local_enr: enr,
external_peer_id: peer_id,
Expand Down
6 changes: 0 additions & 6 deletions beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use state_processing::per_slot_processing;
use std::convert::TryInto;
use std::sync::Arc;
use task_executor::test_utils::TestRuntime;
use tokio::sync::oneshot;
use tokio::time::Duration;
use tree_hash::TreeHash;
use types::application_domain::ApplicationDomain;
Expand Down Expand Up @@ -71,7 +70,6 @@ struct ApiTester {
attester_slashing: AttesterSlashing<E>,
proposer_slashing: ProposerSlashing,
voluntary_exit: SignedVoluntaryExit,
_server_shutdown: oneshot::Sender<()>,
network_rx: NetworkReceivers<E>,
local_enr: Enr,
external_peer_id: PeerId,
Expand Down Expand Up @@ -236,7 +234,6 @@ impl ApiTester {
let ApiServer {
server,
listening_socket: _,
shutdown_tx,
network_rx,
local_enr,
external_peer_id,
Expand Down Expand Up @@ -269,7 +266,6 @@ impl ApiTester {
attester_slashing,
proposer_slashing,
voluntary_exit,
_server_shutdown: shutdown_tx,
network_rx,
local_enr,
external_peer_id,
Expand Down Expand Up @@ -324,7 +320,6 @@ impl ApiTester {
let ApiServer {
server,
listening_socket,
shutdown_tx,
network_rx,
local_enr,
external_peer_id,
Expand Down Expand Up @@ -354,7 +349,6 @@ impl ApiTester {
attester_slashing,
proposer_slashing,
voluntary_exit,
_server_shutdown: shutdown_tx,
network_rx,
local_enr,
external_peer_id,
Expand Down
1 change: 1 addition & 0 deletions watch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ beacon_chain = { path = "../beacon_node/beacon_chain" }
network = { path = "../beacon_node/network" }
testcontainers = "0.14.0"
unused_port = { path = "../common/unused_port" }
task_executor = { path = "../common/task_executor" }
11 changes: 6 additions & 5 deletions watch/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use network::NetworkReceivers;

use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use task_executor::test_utils::TestRuntime;
use tokio::sync::oneshot;
use types::{Hash256, MainnetEthSpec, Slot};
use url::Url;
Expand Down Expand Up @@ -75,7 +76,7 @@ struct TesterBuilder {
pub harness: BeaconChainHarness<EphemeralHarnessType<E>>,
pub config: Config,
_bn_network_rx: NetworkReceivers<E>,
_bn_api_shutdown_tx: oneshot::Sender<()>,
test_runtime: TestRuntime,
}

impl TesterBuilder {
Expand All @@ -92,8 +93,8 @@ impl TesterBuilder {
let ApiServer {
server,
listening_socket: bn_api_listening_socket,
shutdown_tx: _bn_api_shutdown_tx,
network_rx: _bn_network_rx,
test_runtime,
..
} = create_api_server(harness.chain.clone(), harness.logger().clone()).await;
tokio::spawn(server);
Expand Down Expand Up @@ -128,7 +129,7 @@ impl TesterBuilder {
harness,
config,
_bn_network_rx,
_bn_api_shutdown_tx,
test_runtime,
}
}
pub async fn build(self, pool: PgPool) -> Tester {
Expand Down Expand Up @@ -175,7 +176,7 @@ impl TesterBuilder {
config: self.config,
updater,
_bn_network_rx: self._bn_network_rx,
_bn_api_shutdown_tx: self._bn_api_shutdown_tx,
_test_runtime: self.test_runtime,
_watch_shutdown_tx,
}
}
Expand All @@ -193,7 +194,7 @@ struct Tester {
pub config: Config,
pub updater: UpdateHandler<E>,
_bn_network_rx: NetworkReceivers<E>,
_bn_api_shutdown_tx: oneshot::Sender<()>,
_test_runtime: TestRuntime,
_watch_shutdown_tx: oneshot::Sender<()>,
}

Expand Down

0 comments on commit 1f9a7a0

Please sign in to comment.