mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 14:01:02 +00:00
Add a command to purge the relay chain only (#306)
* Add a command to purge the relay chain only * WIP * Update rococo-parachains/src/cli.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Move cli stuff to its own crate * Copyright dates * Test not working for some reason... * WIP * Revert "WIP" This reverts commit f97cd63742c7df822e4a6e52a29db5e0f56b7bfa. * Fix test to use provided relay chain * Apply suggestions from code review Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Add hint about which database could not be purged Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||
// Copyright 2020-2021 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||
// Copyright 2020-2021 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||
// Copyright 2020-2021 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||
// Copyright 2020-2021 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
@@ -15,50 +15,63 @@
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use assert_cmd::cargo::cargo_bin;
|
||||
use std::{convert::TryInto, fs, path::PathBuf, process::Command, thread, time::Duration};
|
||||
use std::{convert::TryInto, process::Command, thread, time::Duration};
|
||||
|
||||
mod common;
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn purge_chain_works() {
|
||||
use nix::{
|
||||
sys::signal::{kill, Signal::SIGINT},
|
||||
unistd::Pid,
|
||||
};
|
||||
fn run_node_and_stop() -> tempfile::TempDir {
|
||||
use nix::{
|
||||
sys::signal::{kill, Signal::SIGINT},
|
||||
unistd::Pid,
|
||||
};
|
||||
|
||||
let base_path = "purge_chain_test";
|
||||
let base_path = tempfile::tempdir().unwrap();
|
||||
|
||||
let _ = fs::remove_dir_all(base_path);
|
||||
let mut cmd = Command::new(cargo_bin("rococo-collator"))
|
||||
.args(&["-d", base_path, "--", "--dev"])
|
||||
.spawn()
|
||||
.unwrap();
|
||||
let mut cmd = Command::new(cargo_bin("rococo-collator"))
|
||||
.args(&["-d"])
|
||||
.arg(base_path.path())
|
||||
.args(&["--"])
|
||||
.spawn()
|
||||
.unwrap();
|
||||
|
||||
// Let it produce some blocks.
|
||||
thread::sleep(Duration::from_secs(30));
|
||||
assert!(
|
||||
cmd.try_wait().unwrap().is_none(),
|
||||
"the process should still be running"
|
||||
);
|
||||
// Let it produce some blocks.
|
||||
thread::sleep(Duration::from_secs(30));
|
||||
assert!(
|
||||
cmd.try_wait().unwrap().is_none(),
|
||||
"the process should still be running"
|
||||
);
|
||||
|
||||
// Stop the process
|
||||
kill(Pid::from_raw(cmd.id().try_into().unwrap()), SIGINT).unwrap();
|
||||
assert!(common::wait_for(&mut cmd, 30)
|
||||
.map(|x| x.success())
|
||||
.unwrap_or_default());
|
||||
// Stop the process
|
||||
kill(Pid::from_raw(cmd.id().try_into().unwrap()), SIGINT).unwrap();
|
||||
assert!(common::wait_for(&mut cmd, 30)
|
||||
.map(|x| x.success())
|
||||
.unwrap_or_default());
|
||||
|
||||
let status = Command::new(cargo_bin("rococo-collator"))
|
||||
.args(&["purge-chain", "-d", base_path, "-y"])
|
||||
.status()
|
||||
.unwrap();
|
||||
assert!(status.success());
|
||||
base_path
|
||||
}
|
||||
|
||||
// Make sure that the `parachain_local_testnet` chain folder exists, but the `db` is deleted.
|
||||
assert!(PathBuf::from(base_path)
|
||||
.join("chains/local_testnet/")
|
||||
.exists());
|
||||
assert!(!PathBuf::from(base_path)
|
||||
.join("chains/local_testnet/db")
|
||||
.exists());
|
||||
// Check that both databases are deleted
|
||||
{
|
||||
let base_path = run_node_and_stop();
|
||||
|
||||
assert!(base_path.path().join("chains/local_testnet/db").exists());
|
||||
assert!(base_path.path().join("polkadot/chains/westend_dev/db").exists());
|
||||
|
||||
let status = Command::new(cargo_bin("rococo-collator"))
|
||||
.args(&["purge-chain", "-d"])
|
||||
.arg(base_path.path())
|
||||
.arg("-y")
|
||||
.status()
|
||||
.unwrap();
|
||||
assert!(status.success());
|
||||
|
||||
// Make sure that the `parachain_local_testnet` chain folder exists, but the `db` is deleted.
|
||||
assert!(base_path.path().join("chains/local_testnet").exists());
|
||||
assert!(!base_path.path().join("chains/local_testnet/db").exists());
|
||||
assert!(base_path.path().join("polkadot/chains/westend_dev").exists());
|
||||
assert!(!base_path.path().join("polkadot/chains/westend_dev/db").exists());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||
// Copyright 2020-2021 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
|
||||
Reference in New Issue
Block a user