mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-16 20:39:10 +00:00
Dedup runtime shutdown
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -9449,6 +9449,7 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_yaml",
|
"serde_yaml",
|
||||||
|
"task_executor",
|
||||||
"testcontainers",
|
"testcontainers",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-postgres",
|
"tokio-postgres",
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ use std::sync::Arc;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use store::MemoryStore;
|
use store::MemoryStore;
|
||||||
use task_executor::test_utils::TestRuntime;
|
use task_executor::test_utils::TestRuntime;
|
||||||
use tokio::sync::{mpsc, oneshot};
|
use tokio::sync::mpsc;
|
||||||
use types::{ChainSpec, EthSpec};
|
use types::{ChainSpec, EthSpec};
|
||||||
|
|
||||||
pub const TCP_PORT: u16 = 42;
|
pub const TCP_PORT: u16 = 42;
|
||||||
@@ -46,7 +46,6 @@ pub struct InteractiveTester<E: EthSpec> {
|
|||||||
pub harness: BeaconChainHarness<EphemeralHarnessType<E>>,
|
pub harness: BeaconChainHarness<EphemeralHarnessType<E>>,
|
||||||
pub client: BeaconNodeHttpClient,
|
pub client: BeaconNodeHttpClient,
|
||||||
pub network_rx: NetworkReceivers<E>,
|
pub network_rx: NetworkReceivers<E>,
|
||||||
_server_shutdown: oneshot::Sender<()>,
|
|
||||||
_test_runtime: TestRuntime,
|
_test_runtime: TestRuntime,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +55,6 @@ pub struct InteractiveTester<E: EthSpec> {
|
|||||||
pub struct ApiServer<E: EthSpec, SFut: Future<Output = ()>> {
|
pub struct ApiServer<E: EthSpec, SFut: Future<Output = ()>> {
|
||||||
pub server: SFut,
|
pub server: SFut,
|
||||||
pub listening_socket: SocketAddr,
|
pub listening_socket: SocketAddr,
|
||||||
pub shutdown_tx: oneshot::Sender<()>,
|
|
||||||
pub network_rx: NetworkReceivers<E>,
|
pub network_rx: NetworkReceivers<E>,
|
||||||
pub local_enr: Enr,
|
pub local_enr: Enr,
|
||||||
pub external_peer_id: PeerId,
|
pub external_peer_id: PeerId,
|
||||||
@@ -105,7 +103,6 @@ impl<E: EthSpec> InteractiveTester<E> {
|
|||||||
let ApiServer {
|
let ApiServer {
|
||||||
server,
|
server,
|
||||||
listening_socket,
|
listening_socket,
|
||||||
shutdown_tx: _server_shutdown,
|
|
||||||
network_rx,
|
network_rx,
|
||||||
test_runtime,
|
test_runtime,
|
||||||
..
|
..
|
||||||
@@ -127,7 +124,6 @@ impl<E: EthSpec> InteractiveTester<E> {
|
|||||||
harness,
|
harness,
|
||||||
client,
|
client,
|
||||||
network_rx,
|
network_rx,
|
||||||
_server_shutdown,
|
|
||||||
_test_runtime: test_runtime,
|
_test_runtime: test_runtime,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -231,17 +227,11 @@ pub async fn create_api_server_on_port<T: BeaconChainTypes>(
|
|||||||
log,
|
log,
|
||||||
});
|
});
|
||||||
|
|
||||||
let (shutdown_tx, shutdown_rx) = oneshot::channel();
|
let (listening_socket, server) = crate::serve(ctx, test_runtime.task_executor.exit()).unwrap();
|
||||||
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();
|
|
||||||
|
|
||||||
ApiServer {
|
ApiServer {
|
||||||
server,
|
server,
|
||||||
listening_socket,
|
listening_socket,
|
||||||
shutdown_tx,
|
|
||||||
network_rx: network_receivers,
|
network_rx: network_receivers,
|
||||||
local_enr: enr,
|
local_enr: enr,
|
||||||
external_peer_id: peer_id,
|
external_peer_id: peer_id,
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ use state_processing::per_slot_processing;
|
|||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use task_executor::test_utils::TestRuntime;
|
use task_executor::test_utils::TestRuntime;
|
||||||
use tokio::sync::oneshot;
|
|
||||||
use tokio::time::Duration;
|
use tokio::time::Duration;
|
||||||
use tree_hash::TreeHash;
|
use tree_hash::TreeHash;
|
||||||
use types::application_domain::ApplicationDomain;
|
use types::application_domain::ApplicationDomain;
|
||||||
@@ -71,7 +70,6 @@ struct ApiTester {
|
|||||||
attester_slashing: AttesterSlashing<E>,
|
attester_slashing: AttesterSlashing<E>,
|
||||||
proposer_slashing: ProposerSlashing,
|
proposer_slashing: ProposerSlashing,
|
||||||
voluntary_exit: SignedVoluntaryExit,
|
voluntary_exit: SignedVoluntaryExit,
|
||||||
_server_shutdown: oneshot::Sender<()>,
|
|
||||||
network_rx: NetworkReceivers<E>,
|
network_rx: NetworkReceivers<E>,
|
||||||
local_enr: Enr,
|
local_enr: Enr,
|
||||||
external_peer_id: PeerId,
|
external_peer_id: PeerId,
|
||||||
@@ -236,7 +234,6 @@ impl ApiTester {
|
|||||||
let ApiServer {
|
let ApiServer {
|
||||||
server,
|
server,
|
||||||
listening_socket: _,
|
listening_socket: _,
|
||||||
shutdown_tx,
|
|
||||||
network_rx,
|
network_rx,
|
||||||
local_enr,
|
local_enr,
|
||||||
external_peer_id,
|
external_peer_id,
|
||||||
@@ -269,7 +266,6 @@ impl ApiTester {
|
|||||||
attester_slashing,
|
attester_slashing,
|
||||||
proposer_slashing,
|
proposer_slashing,
|
||||||
voluntary_exit,
|
voluntary_exit,
|
||||||
_server_shutdown: shutdown_tx,
|
|
||||||
network_rx,
|
network_rx,
|
||||||
local_enr,
|
local_enr,
|
||||||
external_peer_id,
|
external_peer_id,
|
||||||
@@ -324,7 +320,6 @@ impl ApiTester {
|
|||||||
let ApiServer {
|
let ApiServer {
|
||||||
server,
|
server,
|
||||||
listening_socket,
|
listening_socket,
|
||||||
shutdown_tx,
|
|
||||||
network_rx,
|
network_rx,
|
||||||
local_enr,
|
local_enr,
|
||||||
external_peer_id,
|
external_peer_id,
|
||||||
@@ -354,7 +349,6 @@ impl ApiTester {
|
|||||||
attester_slashing,
|
attester_slashing,
|
||||||
proposer_slashing,
|
proposer_slashing,
|
||||||
voluntary_exit,
|
voluntary_exit,
|
||||||
_server_shutdown: shutdown_tx,
|
|
||||||
network_rx,
|
network_rx,
|
||||||
local_enr,
|
local_enr,
|
||||||
external_peer_id,
|
external_peer_id,
|
||||||
|
|||||||
@@ -43,3 +43,4 @@ beacon_chain = { path = "../beacon_node/beacon_chain" }
|
|||||||
network = { path = "../beacon_node/network" }
|
network = { path = "../beacon_node/network" }
|
||||||
testcontainers = "0.14.0"
|
testcontainers = "0.14.0"
|
||||||
unused_port = { path = "../common/unused_port" }
|
unused_port = { path = "../common/unused_port" }
|
||||||
|
task_executor = { path = "../common/task_executor" }
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use network::NetworkReceivers;
|
|||||||
|
|
||||||
use rand::distributions::Alphanumeric;
|
use rand::distributions::Alphanumeric;
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
|
use task_executor::test_utils::TestRuntime;
|
||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
use types::{Hash256, MainnetEthSpec, Slot};
|
use types::{Hash256, MainnetEthSpec, Slot};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
@@ -75,7 +76,7 @@ struct TesterBuilder {
|
|||||||
pub harness: BeaconChainHarness<EphemeralHarnessType<E>>,
|
pub harness: BeaconChainHarness<EphemeralHarnessType<E>>,
|
||||||
pub config: Config,
|
pub config: Config,
|
||||||
_bn_network_rx: NetworkReceivers<E>,
|
_bn_network_rx: NetworkReceivers<E>,
|
||||||
_bn_api_shutdown_tx: oneshot::Sender<()>,
|
test_runtime: TestRuntime,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TesterBuilder {
|
impl TesterBuilder {
|
||||||
@@ -92,8 +93,8 @@ impl TesterBuilder {
|
|||||||
let ApiServer {
|
let ApiServer {
|
||||||
server,
|
server,
|
||||||
listening_socket: bn_api_listening_socket,
|
listening_socket: bn_api_listening_socket,
|
||||||
shutdown_tx: _bn_api_shutdown_tx,
|
|
||||||
network_rx: _bn_network_rx,
|
network_rx: _bn_network_rx,
|
||||||
|
test_runtime,
|
||||||
..
|
..
|
||||||
} = create_api_server(harness.chain.clone(), harness.logger().clone()).await;
|
} = create_api_server(harness.chain.clone(), harness.logger().clone()).await;
|
||||||
tokio::spawn(server);
|
tokio::spawn(server);
|
||||||
@@ -128,7 +129,7 @@ impl TesterBuilder {
|
|||||||
harness,
|
harness,
|
||||||
config,
|
config,
|
||||||
_bn_network_rx,
|
_bn_network_rx,
|
||||||
_bn_api_shutdown_tx,
|
test_runtime,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub async fn build(self, pool: PgPool) -> Tester {
|
pub async fn build(self, pool: PgPool) -> Tester {
|
||||||
@@ -175,7 +176,7 @@ impl TesterBuilder {
|
|||||||
config: self.config,
|
config: self.config,
|
||||||
updater,
|
updater,
|
||||||
_bn_network_rx: self._bn_network_rx,
|
_bn_network_rx: self._bn_network_rx,
|
||||||
_bn_api_shutdown_tx: self._bn_api_shutdown_tx,
|
_test_runtime: self.test_runtime,
|
||||||
_watch_shutdown_tx,
|
_watch_shutdown_tx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,7 +194,7 @@ struct Tester {
|
|||||||
pub config: Config,
|
pub config: Config,
|
||||||
pub updater: UpdateHandler<E>,
|
pub updater: UpdateHandler<E>,
|
||||||
_bn_network_rx: NetworkReceivers<E>,
|
_bn_network_rx: NetworkReceivers<E>,
|
||||||
_bn_api_shutdown_tx: oneshot::Sender<()>,
|
_test_runtime: TestRuntime,
|
||||||
_watch_shutdown_tx: oneshot::Sender<()>,
|
_watch_shutdown_tx: oneshot::Sender<()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user