Skip to content

Commit

Permalink
test purge-db
Browse files Browse the repository at this point in the history
  • Loading branch information
cheme committed Feb 2, 2022
1 parent 6904c7d commit 013f7ad
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion tests/purge_chain_works.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub mod common;

#[tokio::test]
#[cfg(unix)]
async fn purge_chain_works() {
async fn purge_chain_rocksdb_works() {
use nix::{
sys::signal::{kill, Signal::SIGINT},
unistd::Pid,
Expand All @@ -43,6 +43,9 @@ async fn purge_chain_works() {
kill(Pid::from_raw(cmd.id().try_into().unwrap()), SIGINT).unwrap();
// Wait for the node to handle it and exit.
assert!(common::wait_for(&mut cmd, 30).map(|x| x.success()).unwrap_or_default());
assert!(tmpdir.path().join("chains/dev").exists());
assert!(tmpdir.path().join("chains/dev/db/full").exists());
assert!(tmpdir.path().join("chains/dev/db/full/parachains").exists());

// Purge chain
let status = Command::new(cargo_bin("polkadot"))
Expand All @@ -57,3 +60,49 @@ async fn purge_chain_works() {
assert!(tmpdir.path().join("chains/dev").exists());
assert!(!tmpdir.path().join("chains/dev/db/full").exists());
}

#[tokio::test]
#[cfg(unix)]
async fn purge_chain_paritydb_works() {
use nix::{
sys::signal::{kill, Signal::SIGINT},
unistd::Pid,
};

let tmpdir = tempdir().expect("could not create temp dir");

let mut cmd = Command::new(cargo_bin("polkadot"))
.args(&["--dev", "-d"])
.arg(tmpdir.path())
.arg("--database")
.arg("paritydb-experimental")
.spawn()
.unwrap();

// Let it produce 1 block.
common::wait_n_finalized_blocks(1, Duration::from_secs(60)).await.unwrap();

// Send SIGINT to node.
kill(Pid::from_raw(cmd.id().try_into().unwrap()), SIGINT).unwrap();
// Wait for the node to handle it and exit.
assert!(common::wait_for(&mut cmd, 30).map(|x| x.success()).unwrap_or_default());
assert!(tmpdir.path().join("chains/dev").exists());
assert!(tmpdir.path().join("chains/dev/paritydb/full").exists());
assert!(tmpdir.path().join("chains/dev/paritydb/parachains").exists());

// Purge chain
let status = Command::new(cargo_bin("polkadot"))
.args(&["purge-chain", "--dev", "-d"])
.arg(tmpdir.path())
.arg("--database")
.arg("paritydb-experimental")
.arg("-y")
.status()
.unwrap();
assert!(status.success());

// Make sure that the chain folder exists, but `db/full` is deleted.
assert!(tmpdir.path().join("chains/dev").exists());
assert!(!tmpdir.path().join("chains/dev/paritydb/full").exists());
assert!(!tmpdir.path().join("chains/dev/paritydb/parachains").exists()); // TODO this removal is missing
}

0 comments on commit 013f7ad

Please sign in to comment.