mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 09:21:04 +00:00
Update CLI (#53)
* Initial commit Forked at:4a3ffe07e7Parent branch: master * Update substrate: more CLI improvement * Update substrate and polkadot to cecton-cumulus-branch * WIP Forked at:4a3ffe07e7Parent branch: master * Update Cargo.lock * WIP Forked at:4a3ffe07e7Parent branch: master * WIP Forked at:4a3ffe07e7Parent branch: master * Update Cargo.lock * WIP Forked at:4a3ffe07e7Parent branch: master * WIP Forked at:4a3ffe07e7Parent branch: master * Test running node and interrupts * WIP Forked at:4a3ffe07e7Parent branch: master * Update Cargo.lock * Update test/parachain/tests/running_the_node_and_interrupt.rs Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -15,43 +15,42 @@ exit-future = '0.1.4'
|
||||
futures = { version = "0.3.1", features = ["compat"] }
|
||||
log = '0.4.8'
|
||||
parking_lot = '0.9.0'
|
||||
tokio = '0.1.22'
|
||||
trie-root = '0.15.2'
|
||||
codec = { package = 'parity-scale-codec', version = '1.0.0' }
|
||||
structopt = "0.3.3"
|
||||
ctrlc = { version = "3.1.3", features = ["termination"] }
|
||||
itertools = { version = "0.8.2" }
|
||||
|
||||
# Parachain dependencies
|
||||
parachain-runtime = { package = "cumulus-test-parachain-runtime", path = "runtime" }
|
||||
|
||||
# Substrate dependencies
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cumulus-branch" }
|
||||
sp-io = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-service = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-network = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-client = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cecton-cumulus-branch" }
|
||||
sp-io = { git = "https://github.com/paritytech/substrate", branch = "cecton-cumulus-branch" }
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "cecton-cumulus-branch" }
|
||||
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "cecton-cumulus-branch" }
|
||||
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "cecton-cumulus-branch" }
|
||||
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "cecton-cumulus-branch" }
|
||||
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "cecton-cumulus-branch" }
|
||||
sc-service = { git = "https://github.com/paritytech/substrate", branch = "cecton-cumulus-branch" }
|
||||
sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "cecton-cumulus-branch" }
|
||||
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "cecton-cumulus-branch" }
|
||||
sc-network = { git = "https://github.com/paritytech/substrate", branch = "cecton-cumulus-branch" }
|
||||
sc-client = { git = "https://github.com/paritytech/substrate", branch = "cecton-cumulus-branch" }
|
||||
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "cecton-cumulus-branch" }
|
||||
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "cecton-cumulus-branch" }
|
||||
|
||||
# Cumulus dependencies
|
||||
cumulus-consensus = { path = "../../consensus" }
|
||||
cumulus-collator = { path = "../../collator" }
|
||||
|
||||
# Polkadot dependencies
|
||||
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||
polkadot-collator = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "cecton-cumulus-branch" }
|
||||
polkadot-collator = { git = "https://github.com/paritytech/polkadot", branch = "cecton-cumulus-branch" }
|
||||
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "cecton-cumulus-branch" }
|
||||
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "cecton-cumulus-branch" }
|
||||
|
||||
[build-dependencies]
|
||||
vergen = '3.0.4'
|
||||
|
||||
|
||||
[dev-dependencies]
|
||||
assert_cmd = "0.12"
|
||||
nix = "0.17"
|
||||
|
||||
@@ -9,27 +9,27 @@ serde = { version = "1.0.101", optional = true, features = ["derive"] }
|
||||
codec = { package = "parity-scale-codec", version = "1.0.6", default-features = false, features = ["derive"] }
|
||||
|
||||
# Substrate dependencies
|
||||
sp-std = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cumulus-branch" }
|
||||
sp-api = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cumulus-branch" }
|
||||
sp-io = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cumulus-branch" }
|
||||
sp-version = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cumulus-branch" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cumulus-branch" }
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cumulus-branch" }
|
||||
sp-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
sp-offchain = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
sp-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
sp-inherents = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
sp-std = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cecton-cumulus-branch" }
|
||||
sp-api = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cecton-cumulus-branch" }
|
||||
sp-io = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cecton-cumulus-branch" }
|
||||
sp-version = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cecton-cumulus-branch" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cecton-cumulus-branch" }
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cecton-cumulus-branch" }
|
||||
sp-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cecton-cumulus-branch" }
|
||||
sp-offchain = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cecton-cumulus-branch" }
|
||||
sp-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cecton-cumulus-branch" }
|
||||
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cecton-cumulus-branch" }
|
||||
sp-inherents = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cecton-cumulus-branch" }
|
||||
|
||||
frame-support = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cumulus-branch" }
|
||||
frame-executive = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cumulus-branch" }
|
||||
frame-system = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cumulus-branch" }
|
||||
pallet-balances = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cumulus-branch" }
|
||||
pallet-indices = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cumulus-branch" }
|
||||
pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cumulus-branch" }
|
||||
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cumulus-branch" }
|
||||
pallet-sudo = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cumulus-branch" }
|
||||
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
frame-support = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cecton-cumulus-branch" }
|
||||
frame-executive = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cecton-cumulus-branch" }
|
||||
frame-system = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cecton-cumulus-branch" }
|
||||
pallet-balances = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cecton-cumulus-branch" }
|
||||
pallet-indices = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cecton-cumulus-branch" }
|
||||
pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cecton-cumulus-branch" }
|
||||
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cecton-cumulus-branch" }
|
||||
pallet-sudo = { git = "https://github.com/paritytech/substrate", default_features = false, branch = "cecton-cumulus-branch" }
|
||||
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cecton-cumulus-branch" }
|
||||
|
||||
# Cumulus dependencies
|
||||
cumulus-runtime = { path = "../../../runtime", default-features = false }
|
||||
|
||||
@@ -17,12 +17,11 @@
|
||||
use crate::chain_spec;
|
||||
use crate::cli::{Cli, PolkadotCli, Subcommand};
|
||||
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
use futures::{future::Map, FutureExt};
|
||||
use std::sync::Arc;
|
||||
|
||||
use parachain_runtime::Block;
|
||||
|
||||
use sc_cli::{error::{self, Result}, VersionInfo};
|
||||
use sc_cli::{error, VersionInfo};
|
||||
use sc_client::genesis;
|
||||
use sc_service::{Configuration, Roles as ServiceRoles};
|
||||
use sp_core::hexdisplay::HexDisplay;
|
||||
@@ -34,14 +33,17 @@ use polkadot_service::ChainSpec as ChainSpecPolkadot;
|
||||
|
||||
use codec::Encode;
|
||||
use log::info;
|
||||
use structopt::StructOpt;
|
||||
|
||||
const DEFAULT_POLKADOT_RPC_HTTP: &'static str = "127.0.0.1:9934";
|
||||
const DEFAULT_POLKADOT_RPC_WS: &'static str = "127.0.0.1:9945";
|
||||
const DEFAULT_POLKADOT_GRAFANA_PORT: &'static str = "127.0.0.1:9956";
|
||||
|
||||
/// Parse command line arguments into service configuration.
|
||||
pub fn run(version: VersionInfo) -> error::Result<()> {
|
||||
let opt: Cli = sc_cli::from_args(&version);
|
||||
|
||||
let mut config = sc_service::Configuration::default();
|
||||
config.impl_name = "cumulus-test-parachain-collator";
|
||||
let mut config = sc_service::Configuration::new(&version);
|
||||
let mut polkadot_config = Configuration::new(&version);
|
||||
|
||||
match opt.subcommand {
|
||||
Some(Subcommand::Base(subcommand)) => sc_cli::run_subcommand(
|
||||
@@ -78,7 +80,13 @@ pub fn run(version: VersionInfo) -> error::Result<()> {
|
||||
Ok(())
|
||||
},
|
||||
None => {
|
||||
sc_cli::init(&mut config, load_spec, &opt.run.shared_params, &version)?;
|
||||
sc_cli::init(&opt.run.shared_params, &version)?;
|
||||
sc_cli::load_spec(&mut config, &opt.run.shared_params, load_spec)?;
|
||||
sc_cli::update_config_for_running_node(
|
||||
&mut config,
|
||||
opt.run,
|
||||
&version,
|
||||
)?;
|
||||
|
||||
info!("{}", version.name);
|
||||
info!(" version {}", config.full_version());
|
||||
@@ -91,43 +99,24 @@ pub fn run(version: VersionInfo) -> error::Result<()> {
|
||||
// TODO
|
||||
let key = Arc::new(sp_core::Pair::from_seed(&[10; 32]));
|
||||
|
||||
let mut polkadot_config = Configuration::default();
|
||||
polkadot_config.impl_name = "cumulus-test-parachain-collator";
|
||||
polkadot_config.config_dir = config.in_chain_config_dir("polkadot");
|
||||
|
||||
// TODO: parse_address is private
|
||||
/*
|
||||
let rpc_interface: &str = interface_str(opt.run.rpc_external, opt.run.unsafe_rpc_external, opt.run.validator)?;
|
||||
config.rpc_http = Some(parse_address(&format!("{}:{}", rpc_interface, 9934), opt.run.rpc_port)?);
|
||||
let ws_interface: &str = interface_str(opt.run.ws_external, opt.run.unsafe_ws_external, opt.run.validator)?;
|
||||
config.rpc_ws = Some(parse_address(&format!("{}:{}", ws_interface, 9945), opt.run.ws_port)?);
|
||||
let grafana_interface: &str = if opt.run.grafana_external { "0.0.0.0" } else { "127.0.0.1" };
|
||||
config.grafana_port = Some(
|
||||
parse_address(&format!("{}:{}", grafana_interface, 9956), opt.run.grafana_port)?
|
||||
);
|
||||
*/
|
||||
|
||||
let polkadot_opt: PolkadotCli = sc_cli::from_iter(opt.relaychain_args, &version);
|
||||
|
||||
// TODO
|
||||
polkadot_config.chain_spec = Some(sc_cli::load_spec(&polkadot_opt.run.shared_params, load_spec_polkadot)?);
|
||||
// TODO: base_path is private
|
||||
//polkadot_config.config_dir = Some(sc_cli::base_path(&polkadot_opt.run.shared_params, &version));
|
||||
polkadot_config.impl_commit = version.commit;
|
||||
polkadot_config.impl_version = version.version;
|
||||
polkadot_config.rpc_http = Some(DEFAULT_POLKADOT_RPC_HTTP.parse().unwrap());
|
||||
polkadot_config.rpc_ws = Some(DEFAULT_POLKADOT_RPC_WS.parse().unwrap());
|
||||
polkadot_config.grafana_port = Some(DEFAULT_POLKADOT_GRAFANA_PORT.parse().unwrap());
|
||||
|
||||
// TODO
|
||||
if let Some(ref config_dir) = polkadot_config.config_dir {
|
||||
polkadot_config.database = sc_service::config::DatabaseConfig::Path {
|
||||
cache_size: Default::default(),
|
||||
path: config_dir.join("db"),
|
||||
};
|
||||
}
|
||||
// TODO
|
||||
polkadot_config.network.boot_nodes = polkadot_config.network.boot_nodes.clone();
|
||||
polkadot_config.telemetry_endpoints = polkadot_config.expect_chain_spec().telemetry_endpoints().clone();
|
||||
|
||||
sc_cli::update_config_for_running_node(&mut polkadot_config, polkadot_opt.run);
|
||||
sc_cli::load_spec(
|
||||
&mut polkadot_config,
|
||||
&polkadot_opt.run.shared_params,
|
||||
load_spec_polkadot,
|
||||
)?;
|
||||
sc_cli::update_config_for_running_node(
|
||||
&mut polkadot_config,
|
||||
polkadot_opt.run,
|
||||
&version,
|
||||
)?;
|
||||
|
||||
match config.roles {
|
||||
ServiceRoles::LIGHT => unimplemented!("Light client not supported!"),
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#![warn(missing_docs)]
|
||||
#![warn(unused_extern_crates)]
|
||||
|
||||
use itertools::Itertools;
|
||||
use polkadot_primitives::parachain::Id as ParaId;
|
||||
|
||||
mod chain_spec;
|
||||
|
||||
@@ -23,7 +23,13 @@ use sc_network::construct_simple_protocol;
|
||||
use sc_service::{AbstractService, Configuration};
|
||||
use sp_consensus::{BlockImport, Environment, Proposer};
|
||||
use sp_inherents::InherentDataProviders;
|
||||
use sc_cli;
|
||||
use sp_core::crypto::Pair;
|
||||
|
||||
use polkadot_collator::build_collator_service;
|
||||
use polkadot_primitives::parachain::CollatorPair;
|
||||
use polkadot_service::IsKusama;
|
||||
|
||||
use cumulus_collator::CollatorBuilder;
|
||||
|
||||
use futures::{future, task::Spawn, FutureExt, TryFutureExt};
|
||||
|
||||
@@ -76,40 +82,87 @@ macro_rules! new_full_start {
|
||||
}};
|
||||
}
|
||||
|
||||
/// Run the collator with the given `config`.
|
||||
/// Run a collator node with the given parachain `Configuration` and relaychain `Configuration`
|
||||
///
|
||||
/// This function blocks until done.
|
||||
pub fn run_collator<E: sc_service::ChainSpecExtension>(
|
||||
config: Configuration<GenesisConfig, E>,
|
||||
key: Arc<polkadot_primitives::parachain::CollatorPair>,
|
||||
mut parachain_config: Configuration<GenesisConfig, E>,
|
||||
key: Arc<CollatorPair>,
|
||||
polkadot_config: polkadot_collator::Configuration,
|
||||
) -> Result<(), sc_cli::error::Error> {
|
||||
let (builder, inherent_data_providers) = new_full_start!(config);
|
||||
inherent_data_providers
|
||||
.register_provider(sp_timestamp::InherentDataProvider)
|
||||
.unwrap();
|
||||
) -> sc_cli::error::Result<()> {
|
||||
let para_id = crate::PARA_ID;
|
||||
|
||||
let service = builder
|
||||
.with_network_protocol(|_| Ok(NodeProtocol::new()))?
|
||||
.build()?;
|
||||
let proposer_factory = sc_basic_authorship::ProposerFactory {
|
||||
client: service.client(),
|
||||
transaction_pool: service.transaction_pool(),
|
||||
};
|
||||
if polkadot_config.expect_chain_spec().is_kusama() {
|
||||
sc_cli::run_service_until_exit(polkadot_config, |polkadot_config| {
|
||||
parachain_config.task_executor = polkadot_config.task_executor.clone();
|
||||
|
||||
let block_import = service.client();
|
||||
let (builder, inherent_data_providers) = new_full_start!(parachain_config);
|
||||
inherent_data_providers
|
||||
.register_provider(sp_timestamp::InherentDataProvider)
|
||||
.unwrap();
|
||||
|
||||
let setup_parachain = SetupParachain {
|
||||
service,
|
||||
inherent_data_providers,
|
||||
proposer_factory,
|
||||
block_import,
|
||||
};
|
||||
let service = builder
|
||||
.with_network_protocol(|_| Ok(NodeProtocol::new()))?
|
||||
.build()?;
|
||||
let proposer_factory = sc_basic_authorship::ProposerFactory {
|
||||
client: service.client(),
|
||||
transaction_pool: service.transaction_pool(),
|
||||
};
|
||||
|
||||
cumulus_collator::run_collator(
|
||||
setup_parachain,
|
||||
crate::PARA_ID,
|
||||
key,
|
||||
polkadot_config,
|
||||
)
|
||||
let block_import = service.client();
|
||||
|
||||
let setup_parachain = SetupParachain {
|
||||
service,
|
||||
inherent_data_providers,
|
||||
proposer_factory,
|
||||
block_import,
|
||||
};
|
||||
|
||||
let builder = CollatorBuilder::new(setup_parachain);
|
||||
|
||||
build_collator_service(
|
||||
polkadot_service::kusama_new_full(polkadot_config, Some((key.public(), para_id)), None, false, 6000)?,
|
||||
para_id,
|
||||
key,
|
||||
builder,
|
||||
)
|
||||
})
|
||||
} else {
|
||||
sc_cli::run_service_until_exit(polkadot_config, |polkadot_config| {
|
||||
parachain_config.task_executor = polkadot_config.task_executor.clone();
|
||||
|
||||
let (builder, inherent_data_providers) = new_full_start!(parachain_config);
|
||||
inherent_data_providers
|
||||
.register_provider(sp_timestamp::InherentDataProvider)
|
||||
.unwrap();
|
||||
|
||||
let service = builder
|
||||
.with_network_protocol(|_| Ok(NodeProtocol::new()))?
|
||||
.build()?;
|
||||
let proposer_factory = sc_basic_authorship::ProposerFactory {
|
||||
client: service.client(),
|
||||
transaction_pool: service.transaction_pool(),
|
||||
};
|
||||
|
||||
let block_import = service.client();
|
||||
|
||||
let setup_parachain = SetupParachain {
|
||||
service,
|
||||
inherent_data_providers,
|
||||
proposer_factory,
|
||||
block_import,
|
||||
};
|
||||
|
||||
let builder = CollatorBuilder::new(setup_parachain);
|
||||
|
||||
build_collator_service(
|
||||
polkadot_service::polkadot_new_full(polkadot_config, Some((key.public(), para_id)), None, false, 6000)?,
|
||||
para_id,
|
||||
key,
|
||||
builder,
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct SetupParachain<S, PF, BI> {
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use assert_cmd::cargo::cargo_bin;
|
||||
use std::convert::TryInto;
|
||||
use std::process::{Child, Command, ExitStatus};
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn running_the_node_works_and_can_be_interrupted() {
|
||||
use nix::sys::signal::{kill, Signal::{self, SIGINT, SIGTERM}};
|
||||
use nix::unistd::Pid;
|
||||
|
||||
fn wait_for(child: &mut Child, secs: usize) -> Option<ExitStatus> {
|
||||
for _ in 0..secs {
|
||||
match child.try_wait().unwrap() {
|
||||
Some(status) => return Some(status),
|
||||
None => sleep(Duration::from_secs(1)),
|
||||
}
|
||||
}
|
||||
eprintln!("Took to long to exit. Killing...");
|
||||
let _ = child.kill();
|
||||
child.wait().unwrap();
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
fn run_command_and_kill(signal: Signal) {
|
||||
let mut cmd = Command::new(cargo_bin("cumulus-test-parachain-collator")).args(&["--dev", "-d", "interrupt_test"]).spawn().unwrap();
|
||||
sleep(Duration::from_secs(30));
|
||||
assert!(cmd.try_wait().unwrap().is_none(), "the process should still be running");
|
||||
kill(Pid::from_raw(cmd.id().try_into().unwrap()), signal).unwrap();
|
||||
assert_eq!(
|
||||
wait_for(&mut cmd, 30).map(|x| x.success()),
|
||||
Some(true),
|
||||
"the pocess must exit gracefully after signal {}",
|
||||
signal,
|
||||
);
|
||||
}
|
||||
|
||||
run_command_and_kill(SIGINT);
|
||||
run_command_and_kill(SIGTERM);
|
||||
}
|
||||
Reference in New Issue
Block a user