Example #1
0
        public void DoesNotAttemptToAquireLockIfWeCantDeserialise()
        {
            var lockIo    = Substitute.For <ILockIo>();
            var name      = Guid.NewGuid().ToString();
            var semaphore = new LockFileBasedSemaphore(name, TimeSpan.FromSeconds(30), lockIo, Substitute.For <IProcessFinder>());
            var fileLock  = new UnableToDeserialiseLockFile(DateTime.Now);

            lockIo.LockExists(Arg.Any <string>()).Returns(true);
            var result = semaphore.ShouldAquireLock(fileLock);

            Assert.That(result, Is.EqualTo(LockFileBasedSemaphore.AquireLockAction.DontAquireLock));
        }
Example #2
0
        public void AttemptsToAquireLockIfWeCantDeserialiseButFileIsOlderThanLockTimeout()
        {
            var log       = new InMemoryLog();
            var lockIo    = Substitute.For <ILockIo>();
            var name      = Guid.NewGuid().ToString();
            var semaphore = new LockFileBasedSemaphore(name, TimeSpan.FromSeconds(30), lockIo, Substitute.For <IProcessFinder>(), log);
            var fileLock  = new UnableToDeserialiseLockFile(DateTime.Now.Subtract(TimeSpan.FromMinutes(5)));

            lockIo.LockExists(Arg.Any <string>()).Returns(true);
            var result = semaphore.ShouldAquireLock(fileLock);

            Assert.That(result, Is.EqualTo(LockFileBasedSemaphore.AquireLockAction.AquireLock));
            log.Messages.Should().Contain(m => m.Level == InMemoryLog.Level.Warn && m.FormattedMessage == "Lock file existed but was not readable, and has existed for longer than lock timeout. Taking lock.");
        }