From 4f126016985156816577a292ce3f744885ad880b Mon Sep 17 00:00:00 2001 From: jace-ys Date: Mon, 1 Mar 2021 14:35:59 +0800 Subject: [PATCH] Prepare for release --- .github/workflows/ci.yaml | 16 ++++---- Cargo.toml | 13 ++++--- LICENSE | 21 ++++++++++ README.md | 6 +-- examples/example.rs | 8 ++-- src/builder.rs | 60 ++++++++++++++--------------- src/errors.rs | 8 ++-- src/instance.rs | 70 +++++++++++++++++----------------- src/lib.rs | 8 ++-- src/{redlock.rs => redsync.rs} | 66 ++++++++++++++++---------------- 10 files changed, 150 insertions(+), 126 deletions(-) create mode 100644 LICENSE rename src/{redlock.rs => redsync.rs} (80%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 38f17e3..5b290ee 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -13,8 +13,8 @@ jobs: ~/.cargo/registry ~/.cargo/git ./target - key: ${{ runner.os }}-redlock-rs-${{ hashFiles('Cargo.toml') }} - restore-keys: ${{ runner.os }}-redlock-rs- + key: ${{ runner.os }}-redsync-${{ hashFiles('Cargo.toml') }} + restore-keys: ${{ runner.os }}-redsync- - uses: actions-rs/toolchain@v1 with: profile: minimal @@ -34,8 +34,8 @@ jobs: ~/.cargo/registry ~/.cargo/git ./target - key: ${{ runner.os }}-redlock-rs-${{ hashFiles('Cargo.toml') }} - restore-keys: ${{ runner.os }}-redlock-rs- + key: ${{ runner.os }}-redsync-${{ hashFiles('Cargo.toml') }} + restore-keys: ${{ runner.os }}-redsync- - uses: actions-rs/toolchain@v1 with: profile: minimal @@ -57,8 +57,8 @@ jobs: ~/.cargo/registry ~/.cargo/git ./target - key: ${{ runner.os }}-redlock-rs-${{ hashFiles('Cargo.toml') }} - restore-keys: ${{ runner.os }}-redlock-rs- + key: ${{ runner.os }}-redsync-${{ hashFiles('Cargo.toml') }} + restore-keys: ${{ runner.os }}-redsync- - uses: actions-rs/toolchain@v1 with: profile: minimal @@ -80,8 +80,8 @@ jobs: ~/.cargo/registry ~/.cargo/git ./target - key: ${{ runner.os }}-redlock-rs-${{ hashFiles('Cargo.toml') }} - restore-keys: ${{ runner.os }}-redlock-rs- + key: ${{ runner.os }}-redsync-${{ hashFiles('Cargo.toml') }} + restore-keys: ${{ runner.os }}-redsync- - uses: actions-rs/toolchain@v1 with: profile: minimal diff --git a/Cargo.toml b/Cargo.toml index 2471132..b46df5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,15 @@ [package] -name = "redlock-rs" +name = "redsync" version = "0.1.0" authors = ["jace-ys "] edition = "2018" - -[lib] -name = "redlock" -path = "src/lib.rs" +description = "A Rust implementation of Redlock for distributed locks with Redis" +readme = "README.md" +homepage = "https://github.com/jace-ys/redsync" +repository = "https://github.com/jace-ys/redsync" +license-file = "LICENSE" +keywords = ["redsync", "redlock", "redis", "distributed-locks", "distributed-systems"] +categories = ["concurrency", "algorithms"] [[bin]] name = "example" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..426565a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Jace Tan + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 6c69082..f38ef2e 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ [![ci-badge]][ci-workflow] -[ci-badge]: https://github.com/jace-ys/redlock-rs/workflows/ci/badge.svg -[ci-workflow]: https://github.com/jace-ys/redlock-rs/actions?query=workflow%3Aci +[ci-badge]: https://github.com/jace-ys/redsync/workflows/ci/badge.svg +[ci-workflow]: https://github.com/jace-ys/redsync/actions?query=workflow%3Aci -# `redlock-rs` +# Redsync A Rust implementation of [Redlock](https://redis.io/topics/distlock) for distributed locks with Redis. diff --git a/examples/example.rs b/examples/example.rs index 6e59f75..df7ea04 100644 --- a/examples/example.rs +++ b/examples/example.rs @@ -2,7 +2,7 @@ use std::error::Error; use std::thread; use std::time::Duration; -use redlock::{RedisInstance, Redlock, RedlockError}; +use redsync::{RedisInstance, Redsync, RedsyncError}; fn main() { if let Err(err) = run() { @@ -11,7 +11,7 @@ fn main() { } fn run() -> Result<(), Box> { - let dlm = Redlock::new(vec![ + let dlm = Redsync::new(vec![ RedisInstance::new("redis://127.0.0.1:6389")?, RedisInstance::new("redis://127.0.0.1:6399")?, RedisInstance::new("redis://127.0.0.1:6379")?, @@ -35,8 +35,8 @@ fn run() -> Result<(), Box> { match dlm.unlock(&lock1) { Ok(()) => println!("[t = 2] Released 1st lock after 2 seconds!"), - Err(RedlockError::UnlockFailed(err)) => { - if err.includes(RedlockError::InvalidLease) { + Err(RedsyncError::UnlockFailed(err)) => { + if err.includes(RedsyncError::InvalidLease) { println!("[t = 2] Failed to release 1st lock. Lock has expired!") } } diff --git a/src/builder.rs b/src/builder.rs index 5ec0bad..0aba9e4 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1,15 +1,15 @@ use crate::instance::Instance; -use crate::redlock::Redlock; +use crate::redsync::Redsync; use std::time::Duration; -pub struct RedlockBuilder { +pub struct RedsyncBuilder { cluster: Vec, retry_count: u32, retry_delay: Duration, } -impl RedlockBuilder { +impl RedsyncBuilder { pub fn new(cluster: Vec) -> Self { Self { cluster, @@ -28,11 +28,11 @@ impl RedlockBuilder { self } - pub fn build(self) -> Redlock { + pub fn build(self) -> Redsync { let quorum = (self.cluster.len() as u32) / 2 + 1; let retry_jitter = self.retry_delay.as_millis() as f64 * 0.5; - Redlock { + Redsync { cluster: self.cluster, quorum, retry_count: self.retry_count, @@ -46,52 +46,52 @@ impl RedlockBuilder { #[cfg(test)] mod tests { use super::*; - use crate::errors::RedlockError; + use crate::errors::RedsyncError; use crate::instance::RedisInstance; #[test] - fn default() -> Result<(), RedlockError> { + fn default() -> Result<(), RedsyncError> { let cluster = vec![RedisInstance::new("redis://127.0.0.1:6379")?]; - let redlock = RedlockBuilder::new(cluster).build(); + let redsync = RedsyncBuilder::new(cluster).build(); - assert_eq!(redlock.cluster.len(), 1); - assert_eq!(redlock.quorum, 1); - assert_eq!(redlock.retry_count, 3); - assert_eq!(redlock.retry_delay, Duration::from_millis(200)); - assert_eq!(redlock.retry_jitter, 100.0); - assert_eq!(redlock.drift_factor, 0.01); + assert_eq!(redsync.cluster.len(), 1); + assert_eq!(redsync.quorum, 1); + assert_eq!(redsync.retry_count, 3); + assert_eq!(redsync.retry_delay, Duration::from_millis(200)); + assert_eq!(redsync.retry_jitter, 100.0); + assert_eq!(redsync.drift_factor, 0.01); Ok(()) } #[test] - fn retry_count() -> Result<(), RedlockError> { + fn retry_count() -> Result<(), RedsyncError> { let cluster = vec![RedisInstance::new("redis://127.0.0.1:6379")?]; - let redlock = RedlockBuilder::new(cluster).retry_count(5).build(); + let redsync = RedsyncBuilder::new(cluster).retry_count(5).build(); - assert_eq!(redlock.cluster.len(), 1); - assert_eq!(redlock.quorum, 1); - assert_eq!(redlock.retry_count, 5); - assert_eq!(redlock.retry_delay, Duration::from_millis(200)); - assert_eq!(redlock.retry_jitter, 100.0); - assert_eq!(redlock.drift_factor, 0.01); + assert_eq!(redsync.cluster.len(), 1); + assert_eq!(redsync.quorum, 1); + assert_eq!(redsync.retry_count, 5); + assert_eq!(redsync.retry_delay, Duration::from_millis(200)); + assert_eq!(redsync.retry_jitter, 100.0); + assert_eq!(redsync.drift_factor, 0.01); Ok(()) } #[test] - fn retry_delay() -> Result<(), RedlockError> { + fn retry_delay() -> Result<(), RedsyncError> { let cluster = vec![RedisInstance::new("redis://127.0.0.1:6379")?]; - let redlock = RedlockBuilder::new(cluster) + let redsync = RedsyncBuilder::new(cluster) .retry_delay(Duration::from_millis(100)) .build(); - assert_eq!(redlock.cluster.len(), 1); - assert_eq!(redlock.quorum, 1); - assert_eq!(redlock.retry_count, 3); - assert_eq!(redlock.retry_delay, Duration::from_millis(100)); - assert_eq!(redlock.retry_jitter, 50.0); - assert_eq!(redlock.drift_factor, 0.01); + assert_eq!(redsync.cluster.len(), 1); + assert_eq!(redsync.quorum, 1); + assert_eq!(redsync.retry_count, 3); + assert_eq!(redsync.retry_delay, Duration::from_millis(100)); + assert_eq!(redsync.retry_jitter, 50.0); + assert_eq!(redsync.drift_factor, 0.01); Ok(()) } diff --git a/src/errors.rs b/src/errors.rs index 013bbdd..cadfa2c 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -4,7 +4,7 @@ use std::ops::{Deref, DerefMut}; use thiserror::Error; #[derive(Error, Debug, PartialEq)] -pub enum RedlockError { +pub enum RedsyncError { #[error("{0}")] RedisError(#[from] redis::RedisError), #[error("unexpected response from Redis: {0:?}")] @@ -24,7 +24,7 @@ pub enum RedlockError { } #[derive(Debug, Default, PartialEq)] -pub struct MultiError(Vec); +pub struct MultiError(Vec); impl MultiError { pub fn new() -> Self { @@ -35,13 +35,13 @@ impl MultiError { self.clear() } - pub fn includes(&self, e: RedlockError) -> bool { + pub fn includes(&self, e: RedsyncError) -> bool { self.contains(&e) } } impl Deref for MultiError { - type Target = Vec; + type Target = Vec; fn deref(&self) -> &Self::Target { &self.0 diff --git a/src/instance.rs b/src/instance.rs index 6aa3d2c..f1168c2 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -1,12 +1,12 @@ -use crate::errors::RedlockError; -use crate::redlock::Lock; +use crate::errors::RedsyncError; +use crate::redsync::Lock; use std::time::Duration; pub trait Instance { - fn acquire(&self, lock: &Lock) -> Result<(), RedlockError>; - fn extend(&self, lock: &Lock) -> Result<(), RedlockError>; - fn release(&self, lock: &Lock) -> Result<(), RedlockError>; + fn acquire(&self, lock: &Lock) -> Result<(), RedsyncError>; + fn extend(&self, lock: &Lock) -> Result<(), RedsyncError>; + fn release(&self, lock: &Lock) -> Result<(), RedsyncError>; } const LOCK_SCRIPT: &str = "\ @@ -31,8 +31,8 @@ pub struct RedisInstance { } impl RedisInstance { - pub fn new(params: T) -> Result { - let client = redis::Client::open(params).map_err(RedlockError::RedisError)?; + pub fn new(params: T) -> Result { + let client = redis::Client::open(params).map_err(RedsyncError::RedisError)?; Ok(Self { client }) } @@ -42,11 +42,11 @@ impl RedisInstance { } impl Instance for RedisInstance { - fn acquire(&self, lock: &Lock) -> Result<(), RedlockError> { + fn acquire(&self, lock: &Lock) -> Result<(), RedsyncError> { let mut conn = self .client .get_connection_with_timeout(self.timeout(&lock.ttl)) - .map_err(RedlockError::RedisError)?; + .map_err(RedsyncError::RedisError)?; let result = redis::Script::new(LOCK_SCRIPT) .key(&lock.resource) @@ -56,17 +56,17 @@ impl Instance for RedisInstance { match result { Ok(redis::Value::Okay) => Ok(()), - Ok(redis::Value::Nil) => Err(RedlockError::ResourceLocked), - Ok(v) => Err(RedlockError::UnexpectedResponse(v)), - Err(e) => Err(RedlockError::RedisError(e)), + Ok(redis::Value::Nil) => Err(RedsyncError::ResourceLocked), + Ok(v) => Err(RedsyncError::UnexpectedResponse(v)), + Err(e) => Err(RedsyncError::RedisError(e)), } } - fn extend(&self, lock: &Lock) -> Result<(), RedlockError> { + fn extend(&self, lock: &Lock) -> Result<(), RedsyncError> { let mut conn = self .client .get_connection_with_timeout(self.timeout(&lock.ttl)) - .map_err(RedlockError::RedisError)?; + .map_err(RedsyncError::RedisError)?; let result = redis::Script::new(EXTEND_SCRIPT) .key(&lock.resource) @@ -76,17 +76,17 @@ impl Instance for RedisInstance { match result { Ok(redis::Value::Int(1)) => Ok(()), - Ok(redis::Value::Int(0)) => Err(RedlockError::InvalidLease), - Ok(v) => Err(RedlockError::UnexpectedResponse(v)), - Err(e) => Err(RedlockError::RedisError(e)), + Ok(redis::Value::Int(0)) => Err(RedsyncError::InvalidLease), + Ok(v) => Err(RedsyncError::UnexpectedResponse(v)), + Err(e) => Err(RedsyncError::RedisError(e)), } } - fn release(&self, lock: &Lock) -> Result<(), RedlockError> { + fn release(&self, lock: &Lock) -> Result<(), RedsyncError> { let mut conn = self .client .get_connection_with_timeout(self.timeout(&lock.ttl)) - .map_err(RedlockError::RedisError)?; + .map_err(RedsyncError::RedisError)?; let result = redis::Script::new(UNLOCK_SCRIPT) .key(&lock.resource) @@ -95,9 +95,9 @@ impl Instance for RedisInstance { match result { Ok(redis::Value::Int(1)) => Ok(()), - Ok(redis::Value::Int(0)) => Err(RedlockError::InvalidLease), - Ok(v) => Err(RedlockError::UnexpectedResponse(v)), - Err(e) => Err(RedlockError::RedisError(e)), + Ok(redis::Value::Int(0)) => Err(RedsyncError::InvalidLease), + Ok(v) => Err(RedsyncError::UnexpectedResponse(v)), + Err(e) => Err(RedsyncError::RedisError(e)), } } } @@ -130,7 +130,7 @@ mod tests { #[test] fn url_error() { let instance = RedisInstance::new("127.0.0.1:6379"); - assert!(matches!(instance, Err(RedlockError::RedisError { .. }))); + assert!(matches!(instance, Err(RedsyncError::RedisError { .. }))); } #[test] @@ -142,18 +142,18 @@ mod tests { } #[test] - fn acquire_locked_resource() -> Result<(), RedlockError> { + fn acquire_locked_resource() -> Result<(), RedsyncError> { let test = setup("acquire_locked_resource"); test.instance.acquire(&test.lock)?; let attempt = test.instance.acquire(&test.lock); - assert!(matches!(attempt, Err(RedlockError::ResourceLocked))); + assert!(matches!(attempt, Err(RedsyncError::ResourceLocked))); Ok(()) } #[test] - fn extend() -> Result<(), RedlockError> { + fn extend() -> Result<(), RedsyncError> { let mut test = setup("extend"); test.instance.acquire(&test.lock)?; @@ -165,31 +165,31 @@ mod tests { } #[test] - fn extend_invalid_lock() -> Result<(), RedlockError> { + fn extend_invalid_lock() -> Result<(), RedsyncError> { let mut test = setup("extend_invalid_lock"); test.instance.acquire(&test.lock)?; test.lock.value = String::from("2"); let attempt = test.instance.extend(&test.lock); - assert!(matches!(attempt, Err(RedlockError::InvalidLease))); + assert!(matches!(attempt, Err(RedsyncError::InvalidLease))); Ok(()) } #[test] - fn extend_expired_lock() -> Result<(), RedlockError> { + fn extend_expired_lock() -> Result<(), RedsyncError> { let test = setup("extend_expired_lock"); test.instance.acquire(&test.lock)?; thread::sleep(Duration::from_secs(1)); let attempt = test.instance.extend(&test.lock); - assert!(matches!(attempt, Err(RedlockError::InvalidLease))); + assert!(matches!(attempt, Err(RedsyncError::InvalidLease))); Ok(()) } #[test] - fn release() -> Result<(), RedlockError> { + fn release() -> Result<(), RedsyncError> { let test = setup("release"); test.instance.acquire(&test.lock)?; @@ -200,25 +200,25 @@ mod tests { } #[test] - fn release_invalid_lock() -> Result<(), RedlockError> { + fn release_invalid_lock() -> Result<(), RedsyncError> { let mut test = setup("unlock_invalid_lock"); test.instance.acquire(&test.lock)?; test.lock.value = String::from("2"); let attempt = test.instance.release(&test.lock); - assert!(matches!(attempt, Err(RedlockError::InvalidLease))); + assert!(matches!(attempt, Err(RedsyncError::InvalidLease))); Ok(()) } #[test] - fn release_expired_lock() -> Result<(), RedlockError> { + fn release_expired_lock() -> Result<(), RedsyncError> { let test = setup("unlock_expired_lock"); test.instance.acquire(&test.lock)?; thread::sleep(Duration::from_secs(1)); let attempt = test.instance.release(&test.lock); - assert!(matches!(attempt, Err(RedlockError::InvalidLease))); + assert!(matches!(attempt, Err(RedsyncError::InvalidLease))); Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index eba7b23..4025259 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,9 @@ -pub use crate::builder::RedlockBuilder; -pub use crate::errors::{MultiError, RedlockError}; +pub use crate::builder::RedsyncBuilder; +pub use crate::errors::{MultiError, RedsyncError}; pub use crate::instance::{Instance, RedisInstance}; -pub use crate::redlock::{Lock, Redlock}; +pub use crate::redsync::{Lock, Redsync}; mod builder; mod errors; mod instance; -mod redlock; +mod redsync; diff --git a/src/redlock.rs b/src/redsync.rs similarity index 80% rename from src/redlock.rs rename to src/redsync.rs index 707171a..8db8de7 100644 --- a/src/redlock.rs +++ b/src/redsync.rs @@ -1,5 +1,5 @@ -use crate::builder::RedlockBuilder; -use crate::errors::{MultiError, RedlockError}; +use crate::builder::RedsyncBuilder; +use crate::errors::{MultiError, RedsyncError}; use crate::instance::Instance; use std::ops::{Add, Sub}; @@ -16,7 +16,7 @@ pub struct Lock { pub expiry: Instant, } -pub struct Redlock { +pub struct Redsync { pub(crate) cluster: Vec, pub(crate) quorum: u32, pub(crate) retry_count: u32, @@ -30,17 +30,17 @@ enum Call { Extend, } -impl Redlock { +impl Redsync { pub fn new(cluster: Vec) -> Self { - RedlockBuilder::new(cluster).build() + RedsyncBuilder::new(cluster).build() } - pub fn lock(&self, resource: &str, ttl: Duration) -> Result { + pub fn lock(&self, resource: &str, ttl: Duration) -> Result { let value = self.get_unique_lock_id(); self.call(Call::Lock, resource, &value, ttl) } - pub fn extend(&self, lock: &Lock, ttl: Duration) -> Result { + pub fn extend(&self, lock: &Lock, ttl: Duration) -> Result { self.call(Call::Extend, &lock.resource, &lock.value, ttl) } @@ -50,7 +50,7 @@ impl Redlock { resource: &str, value: &str, ttl: Duration, - ) -> Result { + ) -> Result { let drift = Duration::from_millis((ttl.as_millis() as f64 * self.drift_factor) as u64 + 2); let mut errors = MultiError::new(); @@ -90,12 +90,12 @@ impl Redlock { } match call { - Call::Lock => Err(RedlockError::LockRetriesExceeded(errors)), - Call::Extend => Err(RedlockError::ExtendRetriesExceeded(errors)), + Call::Lock => Err(RedsyncError::LockRetriesExceeded(errors)), + Call::Extend => Err(RedsyncError::ExtendRetriesExceeded(errors)), } } - pub fn unlock(&self, lock: &Lock) -> Result<(), RedlockError> { + pub fn unlock(&self, lock: &Lock) -> Result<(), RedsyncError> { let mut n = 0; let mut errors = MultiError::new(); @@ -107,7 +107,7 @@ impl Redlock { } if n < self.quorum { - return Err(RedlockError::UnlockFailed(errors)); + return Err(RedsyncError::UnlockFailed(errors)); } Ok(()) @@ -153,31 +153,31 @@ mod tests { } impl Instance for FakeInstance { - fn acquire(&self, _lock: &Lock) -> Result<(), RedlockError> { + fn acquire(&self, _lock: &Lock) -> Result<(), RedsyncError> { match self.acquire { 1 => Ok(()), - _ => Err(RedlockError::ResourceLocked), + _ => Err(RedsyncError::ResourceLocked), } } - fn extend(&self, _lock: &Lock) -> Result<(), RedlockError> { + fn extend(&self, _lock: &Lock) -> Result<(), RedsyncError> { match self.extend { 1 => Ok(()), - _ => Err(RedlockError::InvalidLease), + _ => Err(RedsyncError::InvalidLease), } } - fn release(&self, _lock: &Lock) -> Result<(), RedlockError> { + fn release(&self, _lock: &Lock) -> Result<(), RedsyncError> { match self.release { 1 => Ok(()), - _ => Err(RedlockError::InvalidLease), + _ => Err(RedsyncError::InvalidLease), } } } #[test] fn lock() { - let dlm = Redlock::new(vec![ + let dlm = Redsync::new(vec![ FakeInstance::new(1, 1, 1), FakeInstance::new(1, 1, 1), FakeInstance::new(0, 1, 1), @@ -194,7 +194,7 @@ mod tests { #[test] fn lock_error() { - let dlm = Redlock::new(vec![ + let dlm = Redsync::new(vec![ FakeInstance::new(0, 1, 1), FakeInstance::new(0, 1, 1), FakeInstance::new(1, 1, 1), @@ -203,13 +203,13 @@ mod tests { let attempt = dlm.lock("test", Duration::from_secs(1)); assert!(matches!( attempt, - Err(RedlockError::LockRetriesExceeded { .. }) + Err(RedsyncError::LockRetriesExceeded { .. }) )); } #[test] - fn extend() -> Result<(), RedlockError> { - let dlm = Redlock::new(vec![ + fn extend() -> Result<(), RedsyncError> { + let dlm = Redsync::new(vec![ FakeInstance::new(1, 1, 1), FakeInstance::new(1, 1, 1), FakeInstance::new(1, 0, 1), @@ -228,8 +228,8 @@ mod tests { } #[test] - fn extend_error() -> Result<(), RedlockError> { - let dlm = Redlock::new(vec![ + fn extend_error() -> Result<(), RedsyncError> { + let dlm = Redsync::new(vec![ FakeInstance::new(1, 0, 1), FakeInstance::new(1, 0, 1), FakeInstance::new(1, 1, 1), @@ -239,15 +239,15 @@ mod tests { let attempt = dlm.extend(&lock, Duration::from_secs(2)); assert!(matches!( attempt, - Err(RedlockError::ExtendRetriesExceeded { .. }) + Err(RedsyncError::ExtendRetriesExceeded { .. }) )); Ok(()) } #[test] - fn unlock() -> Result<(), RedlockError> { - let dlm = Redlock::new(vec![ + fn unlock() -> Result<(), RedsyncError> { + let dlm = Redsync::new(vec![ FakeInstance::new(1, 1, 1), FakeInstance::new(1, 1, 1), FakeInstance::new(1, 1, 0), @@ -261,8 +261,8 @@ mod tests { } #[test] - fn unlock_error() -> Result<(), RedlockError> { - let dlm = Redlock::new(vec![ + fn unlock_error() -> Result<(), RedsyncError> { + let dlm = Redsync::new(vec![ FakeInstance::new(1, 1, 0), FakeInstance::new(1, 1, 0), FakeInstance::new(1, 1, 1), @@ -270,7 +270,7 @@ mod tests { let lock = dlm.lock("test", Duration::from_secs(1))?; let attempt = dlm.unlock(&lock); - assert!(matches!(attempt, Err(RedlockError::UnlockFailed { .. }))); + assert!(matches!(attempt, Err(RedsyncError::UnlockFailed { .. }))); Ok(()) } @@ -278,7 +278,7 @@ mod tests { #[test] fn get_unique_lock_id() { let cluster = vec![FakeInstance::new(1, 1, 1)]; - let dlm = Redlock::new(cluster); + let dlm = Redsync::new(cluster); let value = dlm.get_unique_lock_id(); assert_eq!(value.len(), 20); @@ -288,7 +288,7 @@ mod tests { #[test] fn get_retry_delay() { let cluster = vec![FakeInstance::new(1, 1, 1)]; - let dlm = Redlock::new(cluster); + let dlm = Redsync::new(cluster); let retry_delay = dlm.get_retry_delay(); let (min, max) = (Duration::from_millis(100), Duration::from_millis(300));