Skip to content

Commit

Permalink
added more test for revoke_notify
Browse files Browse the repository at this point in the history
  • Loading branch information
lvboudre committed Nov 22, 2024
1 parent fd9ff1c commit c62c84f
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion tests/test_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ async fn test_managed_lock_revoke_notify_clonability() {
let (tx, rx) = tokio::sync::oneshot::channel();
let lock_key = managed_lock1.get_key();
let revoke_notify1 = managed_lock1.get_revoke_notify();
let revoke_notify2 = managed_lock1.get_revoke_notify();
let revoke_notify2 = revoke_notify1.clone();

let h = tokio::spawn(async move {
managed_lock1
Expand All @@ -184,3 +184,32 @@ async fn test_managed_lock_revoke_notify_clonability() {
let _ = revoke_notify1.wait_for_revoke().await;
let _ = revoke_notify2.wait_for_revoke().await;
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn lock_revoke_notify_should_notify_even_if_lock_is_revoke_before_constructor() {
let etcd = common::get_etcd_client().await;
let managed_lease_factory = ManagedLeaseFactory::new(etcd.clone());
let (_, lock_man) = spawn_lock_manager(etcd.clone(), managed_lease_factory);

let lock_name = random_str(10);

let managed_lock1 = lock_man
.try_lock(lock_name, Duration::from_secs(10))
.await
.expect("failed to lock");

let lock_key = managed_lock1.get_key();
// Revoke the lock before the managed lock is constructed
etcd.kv_client()
.delete(lock_key, None)
.await
.expect("failed to delete key");

// Construction is here
let revoke_notify1 = managed_lock1.get_revoke_notify();
let revoke_notify2 = managed_lock1.get_revoke_notify();

// The lock is already revoked, so the future should return immediately
let _ = revoke_notify1.wait_for_revoke().await;
let _ = revoke_notify2.wait_for_revoke().await;
}

0 comments on commit c62c84f

Please sign in to comment.