public void LockFileInfo_TryAcquire_Test() { var lockFilePath = Path.Combine(TempDirPath, Guid.NewGuid().ToString()); using (var lockFile = LockFile.TryAcquire(lockFilePath)) { Assert.That(lockFile, Is.Not.Null); } }
public void LockFileInfo_WaitAcquire_Cancellation_Test() { var lockFilePath = Path.Combine(TempDirPath, Guid.NewGuid().ToString()); using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(0.5))) using (LockFile.TryAcquire(lockFilePath)) { Assert.Throws <OperationCanceledException>(() => LockFile.WaitAcquire(lockFilePath, cts.Token)); } }
private void EnsureLockFileAcquired() { // Ensure storage directory exists Directory.CreateDirectory(_storageDirPath); // Try to acquire lock file if it's not acquired yet _lockFile = _lockFile ?? LockFile.TryAcquire(_lockFilePath); // If failed to acquire - throw if (_lockFile == null) { throw new LockFileNotAcquiredException(); } }
public void LockFileInfo_WaitAcquire_Test() { var lockFilePath = Path.Combine(TempDirPath, Guid.NewGuid().ToString()); using (var originalLockFile = LockFile.TryAcquire(lockFilePath)) { Task.Delay(TimeSpan.FromSeconds(0.5)).ContinueWith(_ => originalLockFile.Dispose()); using (var newLockFile = LockFile.WaitAcquire(lockFilePath)) { Assert.That(newLockFile, Is.Not.Null); } } }