test folder-deleting guards
This commit is contained in:
parent
c65a5c8e9c
commit
756b7a3e67
@ -296,7 +296,7 @@ impl Service {
|
|||||||
fn replace_client_db(&self) -> Result<(), Error> {
|
fn replace_client_db(&self) -> Result<(), Error> {
|
||||||
let our_db = self.restoration_db();
|
let our_db = self.restoration_db();
|
||||||
|
|
||||||
try!(self.db_restore.restore_db(our_db.to_str().unwrap()));
|
try!(self.db_restore.restore_db(our_db.to_string_lossy()));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ use std::sync::Arc;
|
|||||||
use client::{BlockChainClient, Client};
|
use client::{BlockChainClient, Client};
|
||||||
use ids::BlockID;
|
use ids::BlockID;
|
||||||
use snapshot::service::{Service, ServiceParams};
|
use snapshot::service::{Service, ServiceParams};
|
||||||
use snapshot::SnapshotService;
|
use snapshot::{self, ManifestData, SnapshotService};
|
||||||
use spec::Spec;
|
use spec::Spec;
|
||||||
use tests::helpers::generate_dummy_client_with_spec_and_data;
|
use tests::helpers::generate_dummy_client_with_spec_and_data;
|
||||||
|
|
||||||
@ -29,6 +29,14 @@ use devtools::RandomTempPath;
|
|||||||
use io::IoChannel;
|
use io::IoChannel;
|
||||||
use util::kvdb::DatabaseConfig;
|
use util::kvdb::DatabaseConfig;
|
||||||
|
|
||||||
|
struct NoopDBRestore;
|
||||||
|
|
||||||
|
impl snapshot::DatabaseRestore for NoopDBRestore {
|
||||||
|
fn restore_db(&self, _new_db: &str) -> Result<(), ::error::Error> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn restored_is_equivalent() {
|
fn restored_is_equivalent() {
|
||||||
const NUM_BLOCKS: u32 = 400;
|
const NUM_BLOCKS: u32 = 400;
|
||||||
@ -94,3 +102,40 @@ fn restored_is_equivalent() {
|
|||||||
assert_eq!(block1, block2);
|
assert_eq!(block1, block2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn guards_delete_folders() {
|
||||||
|
let spec = Spec::new_null();
|
||||||
|
let path = RandomTempPath::create_dir();
|
||||||
|
let mut path = path.as_path().clone();
|
||||||
|
let service_params = ServiceParams {
|
||||||
|
engine: spec.engine.clone(),
|
||||||
|
genesis_block: spec.genesis_block(),
|
||||||
|
db_config: DatabaseConfig::with_columns(::db::NUM_COLUMNS),
|
||||||
|
pruning: ::util::journaldb::Algorithm::Archive,
|
||||||
|
channel: IoChannel::disconnected(),
|
||||||
|
snapshot_root: path.clone(),
|
||||||
|
db_restore: Arc::new(NoopDBRestore),
|
||||||
|
};
|
||||||
|
|
||||||
|
let service = Service::new(service_params).unwrap();
|
||||||
|
path.push("restoration");
|
||||||
|
|
||||||
|
let manifest = ManifestData {
|
||||||
|
state_hashes: vec![],
|
||||||
|
block_hashes: vec![],
|
||||||
|
block_number: 0,
|
||||||
|
block_hash: Default::default(),
|
||||||
|
state_root: Default::default(),
|
||||||
|
};
|
||||||
|
|
||||||
|
service.init_restore(manifest).unwrap();
|
||||||
|
|
||||||
|
assert!(path.exists());
|
||||||
|
|
||||||
|
drop(service);
|
||||||
|
|
||||||
|
assert!(!path.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user