diff --git a/Cargo.lock b/Cargo.lock index ba82b20024..8d6d687b0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9449,6 +9449,7 @@ dependencies = [ "serde", "serde_json", "serde_yaml", + "task_executor", "testcontainers", "tokio", "tokio-postgres", diff --git a/beacon_node/http_api/src/test_utils.rs b/beacon_node/http_api/src/test_utils.rs index b0bfd4ffb0..97c4e0b641 100644 --- a/beacon_node/http_api/src/test_utils.rs +++ b/beacon_node/http_api/src/test_utils.rs @@ -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; @@ -46,7 +46,6 @@ pub struct InteractiveTester { pub harness: BeaconChainHarness>, pub client: BeaconNodeHttpClient, pub network_rx: NetworkReceivers, - _server_shutdown: oneshot::Sender<()>, _test_runtime: TestRuntime, } @@ -56,7 +55,6 @@ pub struct InteractiveTester { pub struct ApiServer> { pub server: SFut, pub listening_socket: SocketAddr, - pub shutdown_tx: oneshot::Sender<()>, pub network_rx: NetworkReceivers, pub local_enr: Enr, pub external_peer_id: PeerId, @@ -105,7 +103,6 @@ impl InteractiveTester { let ApiServer { server, listening_socket, - shutdown_tx: _server_shutdown, network_rx, test_runtime, .. @@ -127,7 +124,6 @@ impl InteractiveTester { harness, client, network_rx, - _server_shutdown, _test_runtime: test_runtime, } } @@ -231,17 +227,11 @@ pub async fn create_api_server_on_port( 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, diff --git a/beacon_node/http_api/tests/tests.rs b/beacon_node/http_api/tests/tests.rs index 2b050005b5..4eb681c0b9 100644 --- a/beacon_node/http_api/tests/tests.rs +++ b/beacon_node/http_api/tests/tests.rs @@ -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; @@ -71,7 +70,6 @@ struct ApiTester { attester_slashing: AttesterSlashing, proposer_slashing: ProposerSlashing, voluntary_exit: SignedVoluntaryExit, - _server_shutdown: oneshot::Sender<()>, network_rx: NetworkReceivers, local_enr: Enr, external_peer_id: PeerId, @@ -236,7 +234,6 @@ impl ApiTester { let ApiServer { server, listening_socket: _, - shutdown_tx, network_rx, local_enr, external_peer_id, @@ -269,7 +266,6 @@ impl ApiTester { attester_slashing, proposer_slashing, voluntary_exit, - _server_shutdown: shutdown_tx, network_rx, local_enr, external_peer_id, @@ -324,7 +320,6 @@ impl ApiTester { let ApiServer { server, listening_socket, - shutdown_tx, network_rx, local_enr, external_peer_id, @@ -354,7 +349,6 @@ impl ApiTester { attester_slashing, proposer_slashing, voluntary_exit, - _server_shutdown: shutdown_tx, network_rx, local_enr, external_peer_id, diff --git a/watch/Cargo.toml b/watch/Cargo.toml index d1793a9d06..1ab78de447 100644 --- a/watch/Cargo.toml +++ b/watch/Cargo.toml @@ -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" } diff --git a/watch/tests/tests.rs b/watch/tests/tests.rs index acdda8c306..8364704111 100644 --- a/watch/tests/tests.rs +++ b/watch/tests/tests.rs @@ -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; @@ -75,7 +76,7 @@ struct TesterBuilder { pub harness: BeaconChainHarness>, pub config: Config, _bn_network_rx: NetworkReceivers, - _bn_api_shutdown_tx: oneshot::Sender<()>, + test_runtime: TestRuntime, } impl TesterBuilder { @@ -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); @@ -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 { @@ -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, } } @@ -193,7 +194,7 @@ struct Tester { pub config: Config, pub updater: UpdateHandler, _bn_network_rx: NetworkReceivers, - _bn_api_shutdown_tx: oneshot::Sender<()>, + _test_runtime: TestRuntime, _watch_shutdown_tx: oneshot::Sender<()>, }