Fix inconsistent max_dbs behavior between backends

Signed-off-by: Victor Porof <victor.porof@gmail.com>
without.crypto
Victor Porof 4 years ago
parent 71de0e836d
commit ef64a29fc7
  1. 2
      src/backend/impl_safe/environment.rs
  2. 48
      tests/env-lmdb.rs
  3. 50
      tests/env-safe.rs

@ -230,7 +230,7 @@ impl<'e> BackendEnvironment<'e> for EnvironmentImpl {
let key = name.map(String::from);
let mut dbs = self.dbs.write().map_err(|_| ErrorImpl::EnvPoisonError)?;
let mut arena = self.arena.write().map_err(|_| ErrorImpl::EnvPoisonError)?;
if dbs.keys().filter_map(|k| k.as_ref()).count() >= self.max_dbs {
if dbs.keys().filter_map(|k| k.as_ref()).count() >= self.max_dbs && name != None {
return Err(ErrorImpl::DbsFull);
}
let id = dbs.entry(key).or_insert_with(|| DatabaseImpl(arena.alloc(Database::new(Some(flags), None))));

@ -133,8 +133,8 @@ fn test_open_from_builder_with_dir_2() {
#[test]
#[should_panic(expected = "opened: DbsFull")]
fn test_open_with_capacity() {
let root = Builder::new().prefix("test_open_with_capacity").tempdir().expect("tempdir");
fn test_create_with_capacity_1() {
let root = Builder::new().prefix("test_create_with_capacity").tempdir().expect("tempdir");
println!("Root path: {:?}", root.path());
fs::create_dir_all(root.path()).expect("dir created");
assert!(root.path().is_dir());
@ -150,6 +150,50 @@ fn test_open_with_capacity() {
let _zzz = k.open_single("zzz", StoreOptions::create()).expect("opened");
}
#[test]
fn test_create_with_capacity_2() {
let root = Builder::new().prefix("test_create_with_capacity").tempdir().expect("tempdir");
println!("Root path: {:?}", root.path());
fs::create_dir_all(root.path()).expect("dir created");
assert!(root.path().is_dir());
let k = Rkv::with_capacity::<Lmdb>(root.path(), 1).expect("rkv");
check_rkv(&k);
// This doesn't panic with because even though we specified a capacity of one (database),
// and check_rkv already opened one, the default database doesn't count against the
// limit). This should really return an error rather than panicking, per
// <https://github.com/mozilla/lmdb-rs/issues/6>.
let _zzz = k.open_single(None, StoreOptions::create()).expect("opened");
}
#[test]
#[should_panic(expected = "opened: DbsFull")]
fn test_open_with_capacity_1() {
let root = Builder::new().prefix("test_open_with_capacity").tempdir().expect("tempdir");
println!("Root path: {:?}", root.path());
fs::create_dir_all(root.path()).expect("dir created");
assert!(root.path().is_dir());
let k = Rkv::with_capacity::<Lmdb>(root.path(), 1).expect("rkv");
check_rkv(&k);
let _zzz = k.open_single("zzz", StoreOptions::default()).expect("opened");
}
#[test]
fn test_open_with_capacity_2() {
let root = Builder::new().prefix("test_open_with_capacity").tempdir().expect("tempdir");
println!("Root path: {:?}", root.path());
fs::create_dir_all(root.path()).expect("dir created");
assert!(root.path().is_dir());
let k = Rkv::with_capacity::<Lmdb>(root.path(), 1).expect("rkv");
check_rkv(&k);
let _zzz = k.open_single(None, StoreOptions::default()).expect("opened");
}
fn get_larger_than_default_map_size_value() -> usize {
// The LMDB C library and lmdb Rust crate docs for setting the map size
// <http://www.lmdb.tech/doc/group__mdb.html#gaa2506ec8dab3d969b0e609cd82e619e5>

@ -127,8 +127,8 @@ fn test_open_from_builder_with_dir_safe_2() {
#[test]
#[should_panic(expected = "opened: DbsFull")]
fn test_open_with_capacity_safe() {
let root = Builder::new().prefix("test_open_with_capacity").tempdir().expect("tempdir");
fn test_create_with_capacity_safe_1() {
let root = Builder::new().prefix("test_create_with_capacity_safe").tempdir().expect("tempdir");
println!("Root path: {:?}", root.path());
fs::create_dir_all(root.path()).expect("dir created");
assert!(root.path().is_dir());
@ -136,9 +136,55 @@ fn test_open_with_capacity_safe() {
let k = Rkv::with_capacity::<SafeMode>(root.path(), 1).expect("rkv");
check_rkv(&k);
// This panics with "opened: DbsFull" because we specified a capacity of one (database),
// and check_rkv already opened one (plus the default database, which doesn't count
// against the limit). This should really return an error rather than panicking.
let _zzz = k.open_single("zzz", StoreOptions::create()).expect("opened");
}
#[test]
fn test_create_with_capacity_safe_2() {
let root = Builder::new().prefix("test_create_with_capacity_safe").tempdir().expect("tempdir");
println!("Root path: {:?}", root.path());
fs::create_dir_all(root.path()).expect("dir created");
assert!(root.path().is_dir());
let k = Rkv::with_capacity::<SafeMode>(root.path(), 1).expect("rkv");
check_rkv(&k);
// This doesn't panic with because even though we specified a capacity of one (database),
// and check_rkv already opened one, the default database doesn't count against the
// limit). This should really return an error rather than panicking.
let _zzz = k.open_single(None, StoreOptions::create()).expect("opened");
}
#[test]
#[should_panic(expected = "opened: SafeModeError(DbNotFoundError)")]
fn test_open_with_capacity_safe_1() {
let root = Builder::new().prefix("test_open_with_capacity_safe").tempdir().expect("tempdir");
println!("Root path: {:?}", root.path());
fs::create_dir_all(root.path()).expect("dir created");
assert!(root.path().is_dir());
let k = Rkv::with_capacity::<SafeMode>(root.path(), 1).expect("rkv");
check_rkv(&k);
let _zzz = k.open_single("zzz", StoreOptions::default()).expect("opened");
}
#[test]
fn test_open_with_capacity_safe_2() {
let root = Builder::new().prefix("test_open_with_capacity_safe").tempdir().expect("tempdir");
println!("Root path: {:?}", root.path());
fs::create_dir_all(root.path()).expect("dir created");
assert!(root.path().is_dir());
let k = Rkv::with_capacity::<SafeMode>(root.path(), 1).expect("rkv");
check_rkv(&k);
let _zzz = k.open_single(None, StoreOptions::default()).expect("opened");
}
#[test]
fn test_round_trip_and_transactions_safe() {
let root = Builder::new().prefix("test_round_trip_and_transactions_safe").tempdir().expect("tempdir");

Loading…
Cancel
Save