public void Execute_LockReleasedEnqueued_Signaled() { // ARRANGE var signal = new SemaphoreSlim(0, 1); _jobQueueSemaphoreMock.Setup(m => m.Release("test")) .Callback(() => signal.Release()); // ACT _dbContext.Notifications.InsertOne(NotificationDto.LockReleased("test")); signal.Wait(1000); // ASSERT _jobQueueSemaphoreMock.Verify(m => m.Release(It.IsAny <string>()), Times.Never); _distributedLockMutexMock.Verify(m => m.Release("test"), Times.Once); }
/// <summary> /// Release the lock /// </summary> /// <exception cref="MongoDistributedLockException"></exception> private void Release() { try { if (Logger.IsTraceEnabled()) { Logger.Trace($"{_resource} - Release"); } // Remove resource lock _locks.DeleteOne(new BsonDocument(nameof(DistributedLockDto.Resource), _resource)); _notifications.InsertOne(NotificationDto.LockReleased(_resource), new InsertOneOptions { BypassDocumentValidation = false }); } catch (Exception ex) { throw new MongoDistributedLockException($"{_resource} - Could not release lock.", ex); } }
/// <summary> /// Release the lock /// </summary> /// <exception cref="MongoDistributedLockException"></exception> protected virtual void Release() { try { if (Logger.IsTraceEnabled()) { Logger.Trace($"{_resource} - Release"); } // Remove resource lock _dbContext.DistributedLock.DeleteOne(new BsonDocument(nameof(DistributedLockDto.Resource), _resource)); if (_storageOptions.UseNotificationsCollection) { _dbContext.Notifications.InsertOne(NotificationDto.LockReleased(_resource), new InsertOneOptions { BypassDocumentValidation = false }); } } catch (Exception ex) { throw new MongoDistributedLockException($"{_resource} - Could not release lock.", ex); } }