This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add a few tests for the snapshot service #2059
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b0f6bf2
remove client_db field from snapshot service
rphmeier c65a5c8
add restored_is_equivalent test
rphmeier 756b7a3
test folder-deleting guards
rphmeier ff17174
also test abort_restore
rphmeier bcd9639
Merge github.com:ethcore/parity into snapshot_tests
rphmeier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
|
||
mod blocks; | ||
mod state; | ||
mod service; | ||
|
||
pub mod helpers; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
// Copyright 2015, 2016 Ethcore (UK) Ltd. | ||
// This file is part of Parity. | ||
|
||
// Parity 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. | ||
|
||
// Parity 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 Parity. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! Tests for the snapshot service. | ||
|
||
use std::sync::Arc; | ||
|
||
use client::{BlockChainClient, Client}; | ||
use ids::BlockID; | ||
use snapshot::service::{Service, ServiceParams}; | ||
use snapshot::{self, ManifestData, SnapshotService}; | ||
use spec::Spec; | ||
use tests::helpers::generate_dummy_client_with_spec_and_data; | ||
|
||
use devtools::RandomTempPath; | ||
use io::IoChannel; | ||
use util::kvdb::DatabaseConfig; | ||
|
||
struct NoopDBRestore; | ||
|
||
impl snapshot::DatabaseRestore for NoopDBRestore { | ||
fn restore_db(&self, _new_db: &str) -> Result<(), ::error::Error> { | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[test] | ||
fn restored_is_equivalent() { | ||
const NUM_BLOCKS: u32 = 400; | ||
const TX_PER: usize = 5; | ||
|
||
let gas_prices = vec![1.into(), 2.into(), 3.into(), 999.into()]; | ||
|
||
let client = generate_dummy_client_with_spec_and_data(Spec::new_null, NUM_BLOCKS, TX_PER, &gas_prices); | ||
|
||
let path = RandomTempPath::create_dir(); | ||
let mut path = path.as_path().clone(); | ||
let mut client_db = path.clone(); | ||
|
||
client_db.push("client_db"); | ||
path.push("snapshot"); | ||
|
||
let db_config = DatabaseConfig::with_columns(::db::NUM_COLUMNS); | ||
|
||
let spec = Spec::new_null(); | ||
let client2 = Client::new( | ||
Default::default(), | ||
&spec, | ||
&client_db, | ||
Arc::new(::miner::Miner::with_spec(&spec)), | ||
IoChannel::disconnected(), | ||
&db_config, | ||
).unwrap(); | ||
|
||
let service_params = ServiceParams { | ||
engine: spec.engine.clone(), | ||
genesis_block: spec.genesis_block(), | ||
db_config: db_config, | ||
pruning: ::util::journaldb::Algorithm::Archive, | ||
channel: IoChannel::disconnected(), | ||
snapshot_root: path, | ||
db_restore: client2.clone(), | ||
}; | ||
|
||
let service = Service::new(service_params).unwrap(); | ||
service.take_snapshot(&client, NUM_BLOCKS as u64).unwrap(); | ||
|
||
let manifest = service.manifest().unwrap(); | ||
|
||
service.init_restore(manifest.clone()).unwrap(); | ||
assert!(service.init_restore(manifest.clone()).is_ok()); | ||
|
||
for hash in manifest.state_hashes { | ||
let chunk = service.chunk(hash).unwrap(); | ||
service.feed_state_chunk(hash, &chunk); | ||
} | ||
|
||
for hash in manifest.block_hashes { | ||
let chunk = service.chunk(hash).unwrap(); | ||
service.feed_block_chunk(hash, &chunk); | ||
} | ||
|
||
assert_eq!(service.status(), ::snapshot::RestorationStatus::Inactive); | ||
|
||
for x in 0..NUM_BLOCKS { | ||
let block1 = client.block(BlockID::Number(x as u64)).unwrap(); | ||
let block2 = client2.block(BlockID::Number(x as u64)).unwrap(); | ||
|
||
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.clone()).unwrap(); | ||
assert!(path.exists()); | ||
|
||
service.abort_restore(); | ||
assert!(!path.exists()); | ||
|
||
service.init_restore(manifest.clone()).unwrap(); | ||
assert!(path.exists()); | ||
|
||
drop(service); | ||
assert!(!path.exists()); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the test about btw?
is the name right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's checking if the
Guard
struct in the snapshot service implementation is properly deleting the restoration folder on snapshot abort or drop.