Ensure that OnDemand and HeaderChain share the same cache

This commit is contained in:
Adrian Brink 2017-04-07 17:37:47 +02:00
parent fa88ee148a
commit 2ce5a656e7
1 changed files with 9 additions and 4 deletions

View File

@ -28,7 +28,6 @@ use io::{IoContext, IoError, IoHandler, IoService};
use util::kvdb::{Database, DatabaseConfig};
use cache::Cache;
use time::Duration;
use util::Mutex;
use super::{Client, Config as ClientConfig};
@ -59,8 +58,7 @@ pub struct Service {
impl Service {
/// Start the service: initialize I/O workers and client itself.
pub fn start(config: ClientConfig, spec: &Spec, path: &Path) -> Result<Self, Error> {
let cache = Arc::new(Mutex::new(Cache::new(Default::default(), Duration::hours(6))));
pub fn start(config: ClientConfig, spec: &Spec, path: &Path, cache: Arc<Mutex<Cache>>) -> Result<Self, Error> {
// initialize database.
let mut db_config = DatabaseConfig::with_columns(db::NUM_COLUMNS);
@ -119,11 +117,18 @@ mod tests {
use super::Service;
use devtools::RandomTempPath;
use ethcore::spec::Spec;
use std::sync::Arc;
use cache::Cache;
use time::Duration;
use util::Mutex;
#[test]
fn it_works() {
let spec = Spec::new_test();
let temp_path = RandomTempPath::new();
Service::start(Default::default(), &spec, temp_path.as_path()).unwrap();
let cache = Arc::new(Mutex::new(Cache::new(Default::default(), Duration::hours(6))));
Service::start(Default::default(), &spec, temp_path.as_path(), cache).unwrap();
}
}