Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 2521a18

Browse files
committed
Substrate Companion #9737
paritytech/substrate#9737
1 parent 7229ab8 commit 2521a18

File tree

7 files changed

+22
-27
lines changed

7 files changed

+22
-27
lines changed

cli/src/command.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ pub fn run() -> Result<()> {
411411
use sc_service::TaskManager;
412412
let registry = &runner.config().prometheus_config.as_ref().map(|cfg| &cfg.registry);
413413
let task_manager =
414-
TaskManager::new(runner.config().task_executor.clone(), *registry)
414+
TaskManager::new(runner.config().tokio_handle.clone(), *registry)
415415
.map_err(|e| Error::SubstrateService(sc_service::Error::Prometheus(e)))?;
416416

417417
ensure_dev(chain_spec).map_err(Error::Other)?;

node/test/polkadot-simnet/common/src/lib.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use sp_runtime::{app_crypto::sp_core::H256, generic::Era, AccountId32};
3333
use std::{error::Error, future::Future, str::FromStr};
3434
use support::{weights::Weight, StorageValue};
3535
use test_runner::{
36-
build_runtime, client_parts, task_executor, ChainInfo, ConfigOrChainSpec, Node,
36+
build_runtime, client_parts, ChainInfo, ConfigOrChainSpec, Node,
3737
SignatureVerificationOverride,
3838
};
3939

@@ -360,7 +360,6 @@ where
360360
use structopt::StructOpt;
361361

362362
let tokio_runtime = build_runtime()?;
363-
let task_executor = task_executor(tokio_runtime.handle().clone());
364363
// parse cli args
365364
let cmd = <polkadot_cli::Cli as StructOpt>::from_args();
366365
// set up logging
@@ -369,7 +368,7 @@ where
369368
logger.init()?;
370369

371370
// set up the test-runner
372-
let config = cmd.create_configuration(&cmd.run.base, task_executor)?;
371+
let config = cmd.create_configuration(&cmd.run.base, tokio_runtime.handle().clone())?;
373372
sc_cli::print_node_infos::<polkadot_cli::Cli>(&config);
374373
let (rpc, task_manager, client, pool, command_sink, backend) =
375374
client_parts::<PolkadotChainInfo>(ConfigOrChainSpec::Config(config))?;
@@ -392,11 +391,10 @@ mod tests {
392391
#[test]
393392
fn test_runner() {
394393
let runtime = build_runtime().unwrap();
395-
let task_executor = task_executor(runtime.handle().clone());
396394
let (rpc, task_manager, client, pool, command_sink, backend) =
397395
client_parts::<PolkadotChainInfo>(ConfigOrChainSpec::ChainSpec(
398396
Box::new(polkadot_development_config().unwrap()),
399-
task_executor,
397+
runtime.handle().clone(),
400398
))
401399
.unwrap();
402400
let node =

node/test/service/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ hex = "0.4.3"
1111
tracing = "0.1.26"
1212
rand = "0.8.3"
1313
tempfile = "3.2.0"
14+
tokio = "1.10.0"
1415

1516
# Polkadot dependencies
1617
polkadot-overseer = { path = "../../overseer" }

node/test/service/src/lib.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ use sc_network::{
4141
};
4242
use service::{
4343
config::{DatabaseSource, KeystoreConfig, MultiaddrWithPeerId, WasmExecutionMethod},
44-
BasePath, Configuration, KeepBlocks, Role, RpcHandlers, TaskExecutor, TaskManager,
45-
TransactionStorageMode,
44+
BasePath, Configuration, KeepBlocks, Role, RpcHandlers, TaskManager, TransactionStorageMode,
4645
};
4746
use sp_arithmetic::traits::SaturatedConversion;
4847
use sp_blockchain::HeaderBackend;
@@ -112,7 +111,7 @@ impl ClientHandle for TestClient {
112111
/// and can be used to make adjustments to the runtime genesis storage.
113112
pub fn node_config(
114113
storage_update_func: impl Fn(),
115-
task_executor: TaskExecutor,
114+
tokio_handle: tokio::runtime::Handle,
116115
key: Sr25519Keyring,
117116
boot_nodes: Vec<MultiaddrWithPeerId>,
118117
is_validator: bool,
@@ -149,7 +148,7 @@ pub fn node_config(
149148
impl_name: "polkadot-test-node".to_string(),
150149
impl_version: "0.1".to_string(),
151150
role,
152-
task_executor,
151+
tokio_handle,
153152
transaction_pool: Default::default(),
154153
network: network_config,
155154
keystore: KeystoreConfig::InMemory,
@@ -171,7 +170,6 @@ pub fn node_config(
171170
offchain_worker: sc_client_api::ExecutionStrategy::NativeWhenPossible,
172171
other: sc_client_api::ExecutionStrategy::NativeWhenPossible,
173172
},
174-
rpc_http_threads: None,
175173
rpc_http: None,
176174
rpc_ws: None,
177175
rpc_ipc: None,
@@ -204,13 +202,13 @@ pub fn node_config(
204202
/// The `storage_update_func` function will be executed in an externalities provided environment
205203
/// and can be used to make adjustments to the runtime genesis storage.
206204
pub fn run_validator_node(
207-
task_executor: TaskExecutor,
205+
tokio_handle: tokio::runtime::Handle,
208206
key: Sr25519Keyring,
209207
storage_update_func: impl Fn(),
210208
boot_nodes: Vec<MultiaddrWithPeerId>,
211209
worker_program_path: Option<PathBuf>,
212210
) -> PolkadotTestNode {
213-
let config = node_config(storage_update_func, task_executor, key, boot_nodes, true);
211+
let config = node_config(storage_update_func, tokio_handle, key, boot_nodes, true);
214212
let multiaddr = config.network.listen_addresses[0].clone();
215213
let NewFull { task_manager, client, network, rpc_handlers, overseer_handle, .. } =
216214
new_full(config, IsCollator::No, worker_program_path)
@@ -236,13 +234,13 @@ pub fn run_validator_node(
236234
/// The collator functionality still needs to be registered at the node! This can be done using
237235
/// [`PolkadotTestNode::register_collator`].
238236
pub fn run_collator_node(
239-
task_executor: TaskExecutor,
237+
tokio_handle: tokio::runtime::Handle,
240238
key: Sr25519Keyring,
241239
storage_update_func: impl Fn(),
242240
boot_nodes: Vec<MultiaddrWithPeerId>,
243241
collator_pair: CollatorPair,
244242
) -> PolkadotTestNode {
245-
let config = node_config(storage_update_func, task_executor, key, boot_nodes, false);
243+
let config = node_config(storage_update_func, tokio_handle, key, boot_nodes, false);
246244
let multiaddr = config.network.listen_addresses[0].clone();
247245
let NewFull { task_manager, client, network, rpc_handlers, overseer_handle, .. } =
248246
new_full(config, IsCollator::Yes(collator_pair), None)

node/test/service/tests/build-blocks.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,20 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1616

17-
use futures::{future, pin_mut, select};
17+
use futures::{future, pin_mut, select, FutureExt};
1818
use polkadot_test_service::*;
19-
use service::TaskExecutor;
2019
use sp_keyring::Sr25519Keyring;
2120

2221
#[substrate_test_utils::test]
23-
async fn ensure_test_service_build_blocks(task_executor: TaskExecutor) {
22+
async fn ensure_test_service_build_blocks() {
2423
let mut builder = sc_cli::LoggerBuilder::new("");
2524
builder.with_colors(false);
2625
builder.init().expect("Sets up logger");
2726

2827
let mut alice =
29-
run_validator_node(task_executor.clone(), Sr25519Keyring::Alice, || {}, Vec::new(), None);
28+
run_validator_node(tokio::runtime::Handle::current(), Sr25519Keyring::Alice, || {}, Vec::new(), None);
3029
let mut bob = run_validator_node(
31-
task_executor.clone(),
30+
tokio::runtime::Handle::current(),
3231
Sr25519Keyring::Bob,
3332
|| {},
3433
vec![alice.addr.clone()],

node/test/service/tests/call-function.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1616

1717
use polkadot_test_service::*;
18-
use service::TaskExecutor;
1918
use sp_keyring::Sr25519Keyring::{Alice, Bob};
2019

2120
#[substrate_test_utils::test]
22-
async fn call_function_actually_work(task_executor: TaskExecutor) {
23-
let alice = run_validator_node(task_executor, Alice, || {}, Vec::new(), None);
21+
async fn call_function_actually_work() {
22+
let alice = run_validator_node(tokio::runtime::Handle::current(), Alice, || {}, Vec::new(), None);
2423

2524
let function = polkadot_test_runtime::Call::Balances(pallet_balances::Call::transfer(
2625
Default::default(),

parachain/test-parachains/adder/collator/tests/integration.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const PUPPET_EXE: &str = env!("CARGO_BIN_EXE_adder_collator_puppet_worker");
2121

2222
// If this test is failing, make sure to run all tests with the `real-overseer` feature being enabled.
2323
#[substrate_test_utils::test]
24-
async fn collating_using_adder_collator(task_executor: sc_service::TaskExecutor) {
24+
async fn collating_using_adder_collator() {
2525
use futures::join;
2626
use polkadot_primitives::v1::Id as ParaId;
2727
use sp_keyring::AccountKeyring::*;
@@ -34,7 +34,7 @@ async fn collating_using_adder_collator(task_executor: sc_service::TaskExecutor)
3434

3535
// start alice
3636
let alice = polkadot_test_service::run_validator_node(
37-
task_executor.clone(),
37+
tokio::runtime::Handle::current(),
3838
Alice,
3939
|| {},
4040
vec![],
@@ -43,7 +43,7 @@ async fn collating_using_adder_collator(task_executor: sc_service::TaskExecutor)
4343

4444
// start bob
4545
let bob = polkadot_test_service::run_validator_node(
46-
task_executor.clone(),
46+
tokio::runtime::Handle::current(),
4747
Bob,
4848
|| {},
4949
vec![alice.addr.clone()],
@@ -60,7 +60,7 @@ async fn collating_using_adder_collator(task_executor: sc_service::TaskExecutor)
6060

6161
// run the collator node
6262
let mut charlie = polkadot_test_service::run_collator_node(
63-
task_executor.clone(),
63+
tokio::runtime::Handle::current(),
6464
Charlie,
6565
|| {},
6666
vec![alice.addr.clone(), bob.addr.clone()],

0 commit comments

Comments
 (0)