Esempio n. 1
0
        public void InMemoryMutexCanGetLockAfterTimeoutExpired(int timeoutInMinutes, int addTimeToNow, bool mutexShouldRelease)
        {
            IMutex mutex       = new InMemoryMutex();
            string key         = "mutexkey";
            bool   wasReleased = false;

            mutex.TryGetLock(key, timeoutInMinutes);
            var futureTime = DateTime.UtcNow.AddMinutes(addTimeToNow);

            // Simulate time has passed
            (mutex as InMemoryMutex).Using(new StaticUtcTimeStub(futureTime));

            wasReleased = mutex.TryGetLock(key, timeoutInMinutes);

            Assert.Equal(mutexShouldRelease, wasReleased);
        }
Esempio n. 2
0
        public void InMemoryMutexLocksAndReleases()
        {
            IMutex mutex           = new InMemoryMutex();
            string key             = "mutexkey";
            string otherKey        = "anotherkey";
            int    timeout_24hours = 1440;

            bool firstTry  = mutex.TryGetLock(key, timeout_24hours);
            bool secondTry = mutex.TryGetLock(key, timeout_24hours);

            bool lockOtherKey = mutex.TryGetLock(otherKey, timeout_24hours);

            mutex.Release(key);

            bool thirdTry = mutex.TryGetLock(key, timeout_24hours);

            Assert.True(firstTry);
            Assert.False(secondTry);
            Assert.True(lockOtherKey);
            Assert.True(thirdTry);
        }