Skip to content

Commit

Permalink
extend ttls to help with slow github CI
Browse files Browse the repository at this point in the history
  • Loading branch information
hexcowboy committed Nov 18, 2024
1 parent 1d17163 commit f4f002f
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ mod tests {

redis::cmd("DEL").arg(&*key).exec_async(&mut con).await?;
assert!(
LockManager::lock_instance(&rl.lock_manager_inner.servers[0], &key, val.clone(), 1000)
LockManager::lock_instance(&rl.lock_manager_inner.servers[0], &key, val.clone(), 10_000)
.await
);

Expand Down Expand Up @@ -622,7 +622,7 @@ mod tests {
let rl = LockManager::new(addresses.clone());

let key = rl.get_unique_lock_id()?;
match rl.lock(&key, Duration::from_millis(1000)).await {
match rl.lock(&key, Duration::from_millis(10_000)).await {
Ok(lock) => {
assert_eq!(key, lock.resource);
assert_eq!(20, lock.val.len());
Expand All @@ -647,20 +647,20 @@ mod tests {

let key = rl.get_unique_lock_id()?;

let lock = rl.lock(&key, Duration::from_millis(1000)).await.unwrap();
let lock = rl.lock(&key, Duration::from_millis(10_000)).await.unwrap();
assert!(
lock.validity_time > 0,
"validity time: {}",
lock.validity_time
);

if let Ok(_l) = rl2.lock(&key, Duration::from_millis(1000)).await {
if let Ok(_l) = rl2.lock(&key, Duration::from_millis(10_000)).await {
panic!("Lock acquired, even though it should be locked")
}

rl.unlock(&lock).await;

match rl2.lock(&key, Duration::from_millis(1000)).await {
match rl2.lock(&key, Duration::from_millis(10_000)).await {
Ok(l) => assert!(l.validity_time > 0),
Err(_) => panic!("Lock couldn't be acquired"),
}
Expand All @@ -678,21 +678,21 @@ mod tests {
let key = rl.get_unique_lock_id()?;

async {
let lock_guard = rl.acquire(&key, Duration::from_millis(1000)).await.unwrap();
let lock_guard = rl.acquire(&key, Duration::from_millis(10_000)).await.unwrap();
let lock = &lock_guard.lock;
assert!(
lock.validity_time > 0,
"validity time: {}",
lock.validity_time
);

if let Ok(_l) = rl2.lock(&key, Duration::from_millis(1000)).await {
if let Ok(_l) = rl2.lock(&key, Duration::from_millis(10_000)).await {
panic!("Lock acquired, even though it should be locked")
}
}
.await;

match rl2.lock(&key, Duration::from_millis(1000)).await {
match rl2.lock(&key, Duration::from_millis(10_000)).await {
Ok(l) => assert!(l.validity_time > 0),
Err(_) => panic!("Lock couldn't be acquired"),
}
Expand Down Expand Up @@ -722,13 +722,13 @@ mod tests {
);

// Acquire lock2 and assert it can't be acquired
if let Ok(_l) = rl2.lock(&key, Duration::from_millis(1000)).await {
if let Ok(_l) = rl2.lock(&key, Duration::from_millis(10_000)).await {
panic!("Lock acquired, even though it should be locked")
}
}
.await;

if let Ok(_) = rl2.lock(&key, Duration::from_millis(1000)).await {
if let Ok(_) = rl2.lock(&key, Duration::from_millis(10_000)).await {
panic!("Lock couldn't be acquired");
}

Expand All @@ -747,22 +747,22 @@ mod tests {

async {
let lock1 = rl1
.acquire(&key, Duration::from_millis(1000))
.acquire(&key, Duration::from_millis(10_000))
.await
.unwrap();

// Wait half a second before locking again
tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;

rl1.extend(&lock1.lock, Duration::from_millis(1000))
rl1.extend(&lock1.lock, Duration::from_millis(10_000))
.await
.unwrap();

// Wait another half a second to see if lock2 can unlock
tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;

// Assert lock2 can't access after extended lock
match rl2.lock(&key, Duration::from_millis(1000)).await {
match rl2.lock(&key, Duration::from_millis(10_000)).await {
Ok(_) => panic!("Expected an error when extending the lock but didn't receive one"),
Err(e) => match e {
LockError::Unavailable => (),
Expand Down Expand Up @@ -796,15 +796,15 @@ mod tests {
tokio::time::sleep(tokio::time::Duration::from_millis(1000)).await;

// Assert rl2 can lock with the key now
match rl2.lock(&key, Duration::from_millis(1000)).await {
match rl2.lock(&key, Duration::from_millis(10_000)).await {
Err(_) => {
panic!("Unexpected error when trying to claim free lock after extend expired")
}
_ => (),
}

// Also assert rl1 can't reuse lock1
match rl1.extend(&lock1.lock, Duration::from_millis(1000)).await {
match rl1.extend(&lock1.lock, Duration::from_millis(10_000)).await {
Ok(_) => panic!("Did not expect OK() when re-extending rl1"),
Err(e) => match e {
LockError::Unavailable => (),
Expand Down Expand Up @@ -862,7 +862,7 @@ mod tests {
let rl = LockManager::new(addresses.clone());

let lock = rl
.lock(b"resource", std::time::Duration::from_millis(1000))
.lock(b"resource", std::time::Duration::from_millis(10_000))
.await
.unwrap();

Expand All @@ -885,7 +885,7 @@ mod tests {
let rl = LockManager::new(addresses.clone());

let lock1 = rl
.lock(b"resource_1", std::time::Duration::from_millis(1000))
.lock(b"resource_1", std::time::Duration::from_millis(10_000))
.await
.unwrap();

Expand Down Expand Up @@ -913,7 +913,7 @@ mod tests {
};

let lock2 = rl
.lock(b"resource_2", std::time::Duration::from_millis(1000))
.lock(b"resource_2", std::time::Duration::from_millis(10_000))
.await
.unwrap();
rl.unlock(&lock2).await;
Expand All @@ -933,7 +933,7 @@ mod tests {
let rl = LockManager::new(addresses.clone());

let lock = rl
.lock(b"resource_1", std::time::Duration::from_millis(1000))
.lock(b"resource_1", std::time::Duration::from_millis(10_000))
.await
.unwrap();

Expand Down Expand Up @@ -967,7 +967,7 @@ mod tests {
let rl = LockManager::new(addresses.clone());

let lock = rl
.lock(b"resource_1", std::time::Duration::from_millis(1000))
.lock(b"resource_1", std::time::Duration::from_millis(10_000))
.await
.unwrap();

Expand All @@ -989,7 +989,7 @@ mod tests {
let rl = LockManager::new(addresses.clone());

let lock = rl
.lock(b"resource_2", std::time::Duration::from_millis(1000))
.lock(b"resource_2", std::time::Duration::from_millis(10_000))
.await
.unwrap();

Expand All @@ -1010,7 +1010,7 @@ mod tests {
let rl = LockManager::new(addresses.clone());

let lock = rl
.lock(b"resource_3", std::time::Duration::from_millis(1000))
.lock(b"resource_3", std::time::Duration::from_millis(10_000))
.await
.unwrap();

Expand Down Expand Up @@ -1044,7 +1044,7 @@ mod tests {
let rl = LockManager::new(Vec::<String>::new()); // No Redis clients, simulate failure

let lock_result = rl
.lock(b"resource_4", std::time::Duration::from_millis(1000))
.lock(b"resource_4", std::time::Duration::from_millis(10_000))
.await;

match lock_result {
Expand All @@ -1070,7 +1070,7 @@ mod tests {
let rl = LockManager::new(Vec::<String>::new()); // No Redis clients, simulate failure

let lock_result = rl
.lock(b"resource_5", std::time::Duration::from_millis(1000))
.lock(b"resource_5", std::time::Duration::from_millis(10_000))
.await;

match lock_result {
Expand All @@ -1096,7 +1096,7 @@ mod tests {
let rl = LockManager::new(addresses.clone());

let lock = rl
.lock(b"resource_6", std::time::Duration::from_millis(1000))
.lock(b"resource_6", std::time::Duration::from_millis(10_000))
.await
.unwrap();

Expand Down Expand Up @@ -1130,7 +1130,7 @@ mod tests {
let rl = LockManager::new(addresses.clone());

let lock = rl
.lock(b"resource_7", std::time::Duration::from_millis(1000))
.lock(b"resource_7", std::time::Duration::from_millis(10_000))
.await
.unwrap();

Expand Down

0 comments on commit f4f002f

Please sign in to comment.