From 013f7ad6cb7ab1e74ad3d8cb999bdfa7a189b948 Mon Sep 17 00:00:00 2001 From: cheme Date: Wed, 2 Feb 2022 16:53:37 +0100 Subject: [PATCH] test purge-db --- tests/purge_chain_works.rs | 51 +++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/tests/purge_chain_works.rs b/tests/purge_chain_works.rs index 892c1efe8f83..c0f40cfa463e 100644 --- a/tests/purge_chain_works.rs +++ b/tests/purge_chain_works.rs @@ -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, @@ -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")) @@ -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 +}