From b01b5959061c72e4fc35072cf627ee91f0927b55 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Wed, 5 Jul 2023 11:00:35 +1000 Subject: [PATCH] Hold the `TestRuntime` in tests to prevent BP shutdown --- beacon_node/http_api/src/test_utils.rs | 8 +++++++- beacon_node/http_api/tests/tests.rs | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/beacon_node/http_api/src/test_utils.rs b/beacon_node/http_api/src/test_utils.rs index d2770b5608..b0bfd4ffb0 100644 --- a/beacon_node/http_api/src/test_utils.rs +++ b/beacon_node/http_api/src/test_utils.rs @@ -47,6 +47,7 @@ pub struct InteractiveTester { pub client: BeaconNodeHttpClient, pub network_rx: NetworkReceivers, _server_shutdown: oneshot::Sender<()>, + _test_runtime: TestRuntime, } /// The result of calling `create_api_server`. @@ -59,6 +60,7 @@ pub struct ApiServer> { pub network_rx: NetworkReceivers, pub local_enr: Enr, pub external_peer_id: PeerId, + pub test_runtime: TestRuntime, } type Initializer = Box< @@ -105,6 +107,7 @@ impl InteractiveTester { listening_socket, shutdown_tx: _server_shutdown, network_rx, + test_runtime, .. } = create_api_server(harness.chain.clone(), harness.logger().clone()).await; @@ -125,6 +128,7 @@ impl InteractiveTester { client, network_rx, _server_shutdown, + _test_runtime: test_runtime, } } } @@ -190,9 +194,10 @@ pub async fn create_api_server_on_port( let (beacon_processor_tx, beacon_processor_rx) = mpsc::channel(MAX_WORK_EVENT_QUEUE_LEN); let beacon_processor_send = BeaconProcessorSend(beacon_processor_tx); let (work_reprocessing_tx, work_reprocessing_rx) = mpsc::channel(MAX_SCHEDULED_WORK_QUEUE_LEN); + let test_runtime = TestRuntime::default(); BeaconProcessor { network_globals: network_globals.clone(), - executor: TestRuntime::default().task_executor.clone(), + executor: test_runtime.task_executor.clone(), max_workers: 1, // Single-threaded beacon processor. current_workers: 0, enable_backfill_rate_limiting: chain.config.enable_backfill_rate_limiting, @@ -240,5 +245,6 @@ pub async fn create_api_server_on_port( network_rx: network_receivers, local_enr: enr, external_peer_id: peer_id, + test_runtime, } } diff --git a/beacon_node/http_api/tests/tests.rs b/beacon_node/http_api/tests/tests.rs index 741ee1ffc0..2b050005b5 100644 --- a/beacon_node/http_api/tests/tests.rs +++ b/beacon_node/http_api/tests/tests.rs @@ -30,6 +30,7 @@ use state_processing::per_block_processing::get_expected_withdrawals; 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; @@ -75,6 +76,7 @@ struct ApiTester { local_enr: Enr, external_peer_id: PeerId, mock_builder: Option>>, + _test_runtime: TestRuntime, } struct ApiTesterConfig { @@ -238,6 +240,7 @@ impl ApiTester { network_rx, local_enr, external_peer_id, + test_runtime, } = create_api_server_on_port(chain.clone(), log, port).await; harness.runtime.task_executor.spawn(server, "api_server"); @@ -271,6 +274,7 @@ impl ApiTester { local_enr, external_peer_id, mock_builder, + _test_runtime: test_runtime, } } @@ -324,6 +328,7 @@ impl ApiTester { network_rx, local_enr, external_peer_id, + test_runtime, } = create_api_server(chain.clone(), log).await; harness.runtime.task_executor.spawn(server, "api_server"); @@ -354,6 +359,7 @@ impl ApiTester { local_enr, external_peer_id, mock_builder: None, + _test_runtime: test_runtime, } }