Skip to content

Commit cdd1503

Browse files
committed
feat: lock environment-related tests
1 parent d4f3e43 commit cdd1503

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ license = "MIT"
77
name = "envtestkit"
88
version = "1.0.0"
99

10-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
10+
[features]
11+
default = ["lock"]
12+
lock = ["lazy_static", "parking_lot"]
13+
14+
[dependencies]
15+
lazy_static = { version = "1.4.0", optional = true }
16+
parking_lot = { version = "0.11.0", optional = true }
1117

1218
[dev-dependencies]
1319
fake = "2.2.3"

src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
mod testkit;
1+
#[cfg(feature = "lock")]
2+
#[macro_use]
3+
extern crate lazy_static;
4+
5+
#[cfg(feature = "lock")]
6+
pub mod lock;
27

3-
pub use testkit::set_env;
4-
pub use testkit::EnvironmentTestGuard;
8+
mod testkit;
9+
pub use testkit::*;

src/lock.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use parking_lot::lock_api::{RwLockReadGuard, RwLockWriteGuard};
2+
use parking_lot::RawRwLock;
3+
use parking_lot::RwLock;
4+
5+
lazy_static! {
6+
static ref LOCK: RwLock<()> = RwLock::new(());
7+
}
8+
9+
pub fn lock_read<'a>() -> RwLockReadGuard<'a, RawRwLock, ()> {
10+
LOCK.read()
11+
}
12+
13+
pub fn lock_test<'a>() -> RwLockWriteGuard<'a, RawRwLock, ()> {
14+
LOCK.write()
15+
}

0 commit comments

Comments
 (0)