示例#1
0
        public async Task CantTakeLockOnFirstNodeOfGraphAsync()
        {
            // Arrange
            var vertex1 = new AsyncLockDAGVertex();
            var vertex2 = new AsyncLockDAGVertex();
            var vertex3 = new AsyncLockDAGVertex();
            var vertex4 = new AsyncLockDAGVertex();

            vertex1.AddEdgesTo(vertex2, vertex3);
            vertex2.AddEdgesTo(vertex4);
            vertex3.AddEdgesTo(vertex4);

            var lastLock = await vertex4.GetLockAsync(CancellationToken.None).ConfigureAwait(false);

            // Act
            var firstLockTask = vertex1.GetLockAsync(CancellationToken.None);

            // Assert
            firstLockTask.IsCompleted.Should().BeFalse();

            lastLock.Dispose();

            await Task.Delay(500).ConfigureAwait(false); // Attempts to ensure that task is complete.

            firstLockTask.IsCompleted.Should().BeTrue();
        }
示例#2
0
        public async Task ChildWaitAllParentsLocks()
        {
            // Arrange
            var vertex1 = new AsyncLockDAGVertex();
            var vertex2 = new AsyncLockDAGVertex();
            var vertex3 = new AsyncLockDAGVertex();
            var vertex4 = new AsyncLockDAGVertex();

            vertex1.AddEdgesTo(vertex2, vertex3);
            vertex2.AddEdgesTo(vertex4);
            vertex3.AddEdgesTo(vertex4);

            var lock2 = await vertex2.GetLockAsync(CancellationToken.None).ConfigureAwait(false);

            var lock3 = await vertex3.GetLockAsync(CancellationToken.None).ConfigureAwait(false);

            // Act
            var lock4Task = vertex4.GetLockAsync(CancellationToken.None);

            // Assert
            lock4Task.IsCompleted.Should().BeFalse();

            lock2.Dispose();

            await Task.Delay(500); // Attempts to ensure that task is complete.

            lock4Task.IsCompleted.Should().BeFalse();

            lock3.Dispose();

            await Task.Delay(500); // Attempts to ensure that task is complete.

            lock4Task.IsCompleted.Should().BeTrue();
        }
示例#3
0
        public async Task CantTakeSecondLockOnSingleNodeAsync()
        {
            // Arrange
            var vertex    = new AsyncLockDAGVertex();
            var firstLock = await vertex.GetLockAsync(CancellationToken.None).ConfigureAwait(false);

            // Act
            var secondLockTask = vertex.GetLockAsync(CancellationToken.None);

            // Assert
            secondLockTask.IsCompleted.Should().BeFalse();

            firstLock.Dispose();

            await Task.Delay(500).ConfigureAwait(false); // Attempts to ensure that task is complete.

            secondLockTask.IsCompleted.Should().BeTrue();
        }
示例#4
0
        public async Task LocksIfCanceledIfTokenIsCancelled()
        {
            var cts = new CancellationTokenSource();

            // Arrange
            var vertex = new AsyncLockDAGVertex();

            _ = await vertex.GetLockAsync(cts.Token).ConfigureAwait(false);

            // Act
            var secondLockTask = vertex.GetLockAsync(cts.Token);

            // Assert
            secondLockTask.IsCompleted.Should().BeFalse();

            cts.Cancel();

            await Task.Delay(500).ConfigureAwait(false); // Attempts to ensure that task is complete.

            secondLockTask.IsCanceled.Should().BeTrue();
        }
示例#5
0
        public async Task CanTakeLockOnSingleNodeAsync()
        {
            // Arrange
            var vertex = new AsyncLockDAGVertex();

            // Act
            var exception = await Record.ExceptionAsync(
                async() => await vertex.GetLockAsync(CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false);

            // Assert
            exception.Should().BeNull();
        }
示例#6
0
        public async Task CanTakeLockOnLastNodeOfGraphAsync()
        {
            // Arrange
            var vertex1 = new AsyncLockDAGVertex();
            var vertex2 = new AsyncLockDAGVertex();
            var vertex3 = new AsyncLockDAGVertex();
            var vertex4 = new AsyncLockDAGVertex();

            vertex1.AddEdgesTo(vertex2, vertex3);
            vertex2.AddEdgesTo(vertex4);
            vertex3.AddEdgesTo(vertex4);

            // Act
            var exception = await Record.ExceptionAsync(
                async() => await vertex4.GetLockAsync(CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false);

            // Assert
            exception.Should().BeNull();
        }
示例#7
0
        public async Task ChildsLocksDoesnotBlocksEachOther()
        {
            // Arrange
            var vertex1 = new AsyncLockDAGVertex();
            var vertex2 = new AsyncLockDAGVertex();
            var vertex3 = new AsyncLockDAGVertex();
            var vertex4 = new AsyncLockDAGVertex();

            vertex1.AddEdgesTo(vertex2, vertex3);
            vertex2.AddEdgesTo(vertex4);
            vertex3.AddEdgesTo(vertex4);

            _ = await vertex2.GetLockAsync(CancellationToken.None).ConfigureAwait(false);

            // Act
            var lock3Task = vertex3.GetLockAsync(CancellationToken.None);

            // Assert
            lock3Task.IsCompleted.Should().BeTrue();
        }