public void GlobalLock_Multiple() { using (GlobalLock lock1 = new GlobalLock("a"), lock2 = new GlobalLock("b")) { lock1.Lock(); lock2.Lock(); lock2.Release(); lock1.Release(); } }
public void GlobalLock_Lock() { using (GlobalLock lock1 = new GlobalLock("a"), lock2 = new GlobalLock("a")) { Assert.IsFalse(lock1.IsHeld); Assert.IsFalse(lock2.IsHeld); lock1.Lock(); Assert.IsTrue(lock1.IsHeld); Assert.IsFalse(lock2.IsHeld); lock1.Release(); Assert.IsFalse(lock1.IsHeld); lock1.Lock(); Assert.IsTrue(lock1.IsHeld); try { lock2.Lock(); Assert.Fail(); } catch (GlobalLockException) { // I'm expecting this to fail } lock1.Lock(); Assert.IsTrue(lock1.IsHeld); lock1.Release(); Assert.IsTrue(lock1.IsHeld); try { lock2.Lock(); Assert.Fail(); } catch (GlobalLockException) { // I'm expecting this to fail } lock1.Release(); Assert.IsFalse(lock1.IsHeld); lock2.Lock(); Assert.IsTrue(lock2.IsHeld); try { lock1.Lock(); Assert.Fail(); } catch (GlobalLockException) { // I'm expecting this to fail } lock2.Release(); Assert.IsFalse(lock2.IsHeld); } }