Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
util crates use tempdir crate instead of devtools to create temp path (
Browse files Browse the repository at this point in the history
…#6807)

* use tempdir instead of devtools in kvdb-rocksdb

* use tempdir instead of devtools in migration

* use tempdir instead of devtools in ethcore-network

* fixed wrong merge
  • Loading branch information
debris authored and arkpar committed Oct 20, 2017
1 parent 7b14907 commit 9228ce4
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 61 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ rlp = { path = "rlp" }
heapsize = "0.4"
hash = { path = "hash" }
clippy = { version = "0.0.103", optional = true}
ethcore-devtools = { path = "../devtools" }
libc = "0.2.7"
target_info = "0.1"
ethcore-bigint = { path = "bigint", features = ["heapsizeof"] }
Expand Down
8 changes: 5 additions & 3 deletions util/kvdb-rocksdb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]

[dependencies]
log = "0.3"
elastic-array = "0.9"
ethcore-bigint = { path = "../bigint" }
ethcore-devtools = { path = "../../devtools" }
kvdb = { path = "../kvdb" }
log = "0.3"
parking_lot = "0.4"
regex = "0.2"
rlp = { path = "../rlp" }
rocksdb = { git = "https://github.com/paritytech/rust-rocksdb" }
kvdb = { path = "../kvdb" }

[dev-dependencies]
tempdir = "0.3"
27 changes: 14 additions & 13 deletions util/kvdb-rocksdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ extern crate regex;
extern crate rocksdb;

extern crate ethcore_bigint as bigint;
extern crate ethcore_devtools as devtools;
extern crate kvdb;
extern crate rlp;

Expand Down Expand Up @@ -679,14 +678,16 @@ impl Drop for Database {

#[cfg(test)]
mod tests {
extern crate tempdir;

use std::str::FromStr;
use self::tempdir::TempDir;
use bigint::hash::H256;
use super::*;
use devtools::*;
use std::str::FromStr;

fn test_db(config: &DatabaseConfig) {
let path = RandomTempPath::create_dir();
let db = Database::open(config, path.as_path().to_str().unwrap()).unwrap();
let tempdir = TempDir::new("").unwrap();
let db = Database::open(config, tempdir.path().to_str().unwrap()).unwrap();
let key1 = H256::from_str("02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc").unwrap();
let key2 = H256::from_str("03c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc").unwrap();
let key3 = H256::from_str("01c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc").unwrap();
Expand Down Expand Up @@ -739,8 +740,8 @@ mod tests {

#[test]
fn kvdb() {
let path = RandomTempPath::create_dir();
let _ = Database::open_default(path.as_path().to_str().unwrap()).unwrap();
let tempdir = TempDir::new("").unwrap();
let _ = Database::open_default(tempdir.path().to_str().unwrap()).unwrap();
test_db(&DatabaseConfig::default());
}

Expand All @@ -759,11 +760,11 @@ mod tests {
let config = DatabaseConfig::default();
let config_5 = DatabaseConfig::with_columns(Some(5));

let path = RandomTempPath::create_dir();
let tempdir = TempDir::new("").unwrap();

// open empty, add 5.
{
let db = Database::open(&config, path.as_path().to_str().unwrap()).unwrap();
let db = Database::open(&config, tempdir.path().to_str().unwrap()).unwrap();
assert_eq!(db.num_columns(), 0);

for i in 0..5 {
Expand All @@ -774,7 +775,7 @@ mod tests {

// reopen as 5.
{
let db = Database::open(&config_5, path.as_path().to_str().unwrap()).unwrap();
let db = Database::open(&config_5, tempdir.path().to_str().unwrap()).unwrap();
assert_eq!(db.num_columns(), 5);
}
}
Expand All @@ -784,11 +785,11 @@ mod tests {
let config = DatabaseConfig::default();
let config_5 = DatabaseConfig::with_columns(Some(5));

let path = RandomTempPath::create_dir();
let tempdir = TempDir::new("").unwrap();

// open 5, remove all.
{
let db = Database::open(&config_5, path.as_path().to_str().unwrap()).unwrap();
let db = Database::open(&config_5, tempdir.path().to_str().unwrap()).unwrap();
assert_eq!(db.num_columns(), 5);

for i in (0..5).rev() {
Expand All @@ -799,7 +800,7 @@ mod tests {

// reopen as 0.
{
let db = Database::open(&config, path.as_path().to_str().unwrap()).unwrap();
let db = Database::open(&config, tempdir.path().to_str().unwrap()).unwrap();
assert_eq!(db.num_columns(), 0);
}
}
Expand Down
4 changes: 3 additions & 1 deletion util/migration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ log = "0.3"
macros = { path = "../macros" }
kvdb = { path = "../kvdb" }
kvdb-rocksdb = { path = "../kvdb-rocksdb" }
ethcore-devtools = { path = "../../devtools" }
error-chain = "0.11.0"

[dev-dependencies]
tempdir = "0.3"
5 changes: 0 additions & 5 deletions util/migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ extern crate macros;
#[macro_use]
extern crate error_chain;

extern crate ethcore_devtools as devtools;
extern crate kvdb;
extern crate kvdb_rocksdb;

Expand All @@ -38,10 +37,6 @@ use kvdb::DBTransaction;
use kvdb_rocksdb::{CompactionProfile, Database, DatabaseConfig};

error_chain! {
types {
Error, ErrorKind, ResultExt, Result;
}

links {
Db(kvdb::Error, kvdb::ErrorKind);
}
Expand Down
49 changes: 25 additions & 24 deletions util/migration/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@
//! A random temp directory is created. A database is created within it, and migrations
//! are performed in temp sub-directories.

extern crate tempdir;

use std::collections::BTreeMap;
use std::sync::Arc;
use std::path::{Path, PathBuf};
use {Batch, Config, Error, SimpleMigration, Migration, Manager, ChangeColumns};
use std::sync::Arc;
use self::tempdir::TempDir;
use kvdb_rocksdb::Database;
use devtools::RandomTempPath;
use {Batch, Config, Error, SimpleMigration, Migration, Manager, ChangeColumns};

#[inline]
fn db_path(path: &Path) -> PathBuf {
let mut p = path.to_owned();
p.push("db");
p
path.join("db")
}

// initialize a database at the given directory with the given values.
Expand Down Expand Up @@ -109,8 +110,8 @@ impl Migration for AddsColumn {

#[test]
fn one_simple_migration() {
let dir = RandomTempPath::create_dir();
let db_path = db_path(dir.as_path());
let tempdir = TempDir::new("").unwrap();
let db_path = db_path(tempdir.path());
let mut manager = Manager::new(Config::default());
make_db(&db_path, map![vec![] => vec![], vec![1] => vec![1]]);
let expected = map![vec![0x11] => vec![0x22], vec![1, 0x11] => vec![1, 0x22]];
Expand All @@ -124,8 +125,8 @@ fn one_simple_migration() {
#[test]
#[should_panic]
fn no_migration_needed() {
let dir = RandomTempPath::create_dir();
let db_path = db_path(dir.as_path());
let tempdir = TempDir::new("").unwrap();
let db_path = db_path(tempdir.path());
let mut manager = Manager::new(Config::default());
make_db(&db_path, map![vec![] => vec![], vec![1] => vec![1]]);

Expand All @@ -136,8 +137,8 @@ fn no_migration_needed() {
#[test]
#[should_panic]
fn wrong_adding_order() {
let dir = RandomTempPath::create_dir();
let db_path = db_path(dir.as_path());
let tempdir = TempDir::new("").unwrap();
let db_path = db_path(tempdir.path());
let mut manager = Manager::new(Config::default());
make_db(&db_path, map![vec![] => vec![], vec![1] => vec![1]]);

Expand All @@ -147,8 +148,8 @@ fn wrong_adding_order() {

#[test]
fn multiple_migrations() {
let dir = RandomTempPath::create_dir();
let db_path = db_path(dir.as_path());
let tempdir = TempDir::new("").unwrap();
let db_path = db_path(tempdir.path());
let mut manager = Manager::new(Config::default());
make_db(&db_path, map![vec![] => vec![], vec![1] => vec![1]]);
let expected = map![vec![0x11] => vec![], vec![1, 0x11] => vec![]];
Expand All @@ -162,8 +163,8 @@ fn multiple_migrations() {

#[test]
fn second_migration() {
let dir = RandomTempPath::create_dir();
let db_path = db_path(dir.as_path());
let tempdir = TempDir::new("").unwrap();
let db_path = db_path(tempdir.path());
let mut manager = Manager::new(Config::default());
make_db(&db_path, map![vec![] => vec![], vec![1] => vec![1]]);
let expected = map![vec![] => vec![], vec![1] => vec![]];
Expand All @@ -177,8 +178,8 @@ fn second_migration() {

#[test]
fn first_and_noop_migration() {
let dir = RandomTempPath::create_dir();
let db_path = db_path(dir.as_path());
let tempdir = TempDir::new("").unwrap();
let db_path = db_path(tempdir.path());
let mut manager = Manager::new(Config::default());
make_db(&db_path, map![vec![] => vec![], vec![1] => vec![1]]);
let expected = map![vec![0x11] => vec![0x22], vec![1, 0x11] => vec![1, 0x22]];
Expand All @@ -191,8 +192,8 @@ fn first_and_noop_migration() {

#[test]
fn noop_and_second_migration() {
let dir = RandomTempPath::create_dir();
let db_path = db_path(dir.as_path());
let tempdir = TempDir::new("").unwrap();
let db_path = db_path(tempdir.path());
let mut manager = Manager::new(Config::default());
make_db(&db_path, map![vec![] => vec![], vec![1] => vec![1]]);
let expected = map![vec![] => vec![], vec![1] => vec![]];
Expand All @@ -219,8 +220,8 @@ fn pre_columns() {
let mut manager = Manager::new(Config::default());
manager.add_migration(AddsColumn).unwrap();

let dir = RandomTempPath::create_dir();
let db_path = db_path(dir.as_path());
let tempdir = TempDir::new("").unwrap();
let db_path = db_path(tempdir.path());

// this shouldn't fail to open the database even though it's one column
// short of the one before it.
Expand All @@ -238,8 +239,8 @@ fn change_columns() {
version: 1,
}).unwrap();

let dir = RandomTempPath::create_dir();
let db_path = db_path(dir.as_path());
let tempdir = TempDir::new("").unwrap();
let db_path = db_path(tempdir.path());

let new_path = manager.execute(&db_path, 0).unwrap();

Expand Down
5 changes: 4 additions & 1 deletion util/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ ethcore-io = { path = "../io" }
ethcore-util = { path = ".." }
ethcore-bigint = { path = "../bigint" }
ethcore-bytes = { path = "../bytes" }
ethcore-devtools = { path = "../../devtools" }
ethkey = { path = "../../ethkey" }
ethcrypto = { path = "../../ethcrypto" }
rlp = { path = "../rlp" }
Expand All @@ -36,6 +35,10 @@ hash = { path = "../hash" }
snappy = { path = "../snappy" }
serde_json = "1.0"

[dev-dependencies]
ethcore-devtools = { path = "../../devtools" }
tempdir = "0.3"

[features]
default = []
dev = ["clippy"]
2 changes: 1 addition & 1 deletion util/network/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ mod tests {
use mio::{Ready};
use std::collections::VecDeque;
use ethcore_bytes::Bytes;
use devtools::*;
use devtools::TestSocket;
use io::*;

impl GenericSocket for TestSocket {}
Expand Down
9 changes: 5 additions & 4 deletions util/network/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1267,11 +1267,12 @@ fn load_key(path: &Path) -> Option<Secret> {

#[test]
fn key_save_load() {
use ::devtools::RandomTempPath;
let temp_path = RandomTempPath::create_dir();
use tempdir::TempDir;

let tempdir = TempDir::new("").unwrap();
let key = H256::random().into();
save_key(temp_path.as_path(), &key);
let r = load_key(temp_path.as_path());
save_key(tempdir.path(), &key);
let r = load_key(tempdir.path());
assert_eq!(key, r.unwrap());
}

Expand Down
3 changes: 3 additions & 0 deletions util/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ extern crate log;
#[cfg(test)]
extern crate ethcore_devtools as devtools;

#[cfg(test)]
extern crate tempdir;

mod host;
mod connection;
mod handshake;
Expand Down
8 changes: 4 additions & 4 deletions util/network/src/node_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ mod tests {
use std::net::{SocketAddr, SocketAddrV4, Ipv4Addr};
use bigint::hash::H512;
use std::str::FromStr;
use devtools::*;
use tempdir::TempDir;
use ipnetwork::IpNetwork;

#[test]
Expand Down Expand Up @@ -429,20 +429,20 @@ mod tests {

#[test]
fn table_save_load() {
let temp_path = RandomTempPath::create_dir();
let tempdir = TempDir::new("").unwrap();
let node1 = Node::from_str("enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@22.99.55.44:7770").unwrap();
let node2 = Node::from_str("enode://b979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@22.99.55.44:7770").unwrap();
let id1 = H512::from_str("a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c").unwrap();
let id2 = H512::from_str("b979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c").unwrap();
{
let mut table = NodeTable::new(Some(temp_path.as_path().to_str().unwrap().to_owned()));
let mut table = NodeTable::new(Some(tempdir.path().to_str().unwrap().to_owned()));
table.add_node(node1);
table.add_node(node2);
table.note_failure(&id2);
}

{
let table = NodeTable::new(Some(temp_path.as_path().to_str().unwrap().to_owned()));
let table = NodeTable::new(Some(tempdir.path().to_str().unwrap().to_owned()));
let r = table.nodes(IpFilter::default());
assert_eq!(r[0][..], id1[..]);
assert_eq!(r[1][..], id2[..]);
Expand Down

0 comments on commit 9228ce4

Please sign in to comment.