< Summary

Class:Azure.Core.TestFramework.AsyncGate`2
Assembly:Azure.Core.TestFramework
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core.TestFramework\src\AsyncGate.cs
Covered lines:32
Uncovered lines:1
Coverable lines:33
Total lines:75
Line coverage:96.9% (32 of 33)
Covered branches:1
Total branches:2
Branch coverage:50% (1 of 2)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor()-100%100%
WaitForSignal()-100%100%
Cycle()-100%100%
CycleWithException()-100%100%
Release(...)-100%100%
ReleaseWithException(...)-100%100%
Reset()-87.5%50%
WaitForRelease(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\core\Azure.Core.TestFramework\src\AsyncGate.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Threading.Tasks;
 6
 7namespace Azure.Core.TestFramework
 8{
 9    public class AsyncGate<TIn, TOut>
 10    {
 1528111        private readonly object _sync = new object();
 1528112        private TaskCompletionSource<TIn> _signalTaskCompletionSource = new TaskCompletionSource<TIn>(TaskCreationOption
 1528113        private TaskCompletionSource<TOut> _releaseTaskCompletionSource = new TaskCompletionSource<TOut>(TaskCreationOpt
 14
 15        public async Task<TIn> WaitForSignal()
 16        {
 60217            return await _signalTaskCompletionSource.Task.TimeoutAfterDefault();
 60218        }
 19
 20        public async Task<TIn> Cycle(TOut value = default)
 21        {
 53822            TIn signal = await WaitForSignal();
 53823            Release(value);
 53824            return signal;
 53825        }
 26
 27        public async Task<TIn> CycleWithException(Exception exception)
 28        {
 6429            TIn signal = await WaitForSignal();
 6430            ReleaseWithException(exception);
 6431            return signal;
 6432        }
 33
 34        public void Release(TOut value = default)
 35        {
 53836            lock (_sync)
 37            {
 53838                Reset().SetResult(value);
 53839            }
 53840        }
 41
 42        public void ReleaseWithException(Exception exception)
 43        {
 6444            lock (_sync)
 45            {
 6446                Reset().SetException(exception);
 6447            }
 6448        }
 49
 50        private TaskCompletionSource<TOut> Reset()
 51        {
 60252            lock (_sync)
 53            {
 60254                if (!_signalTaskCompletionSource.Task.IsCompleted)
 55                {
 056                    throw new InvalidOperationException("No await call to release");
 57                }
 58
 60259                TaskCompletionSource<TOut> releaseTaskCompletionSource = _releaseTaskCompletionSource;
 60260                _releaseTaskCompletionSource = new TaskCompletionSource<TOut>(TaskCreationOptions.RunContinuationsAsynch
 60261                _signalTaskCompletionSource = new TaskCompletionSource<TIn>(TaskCreationOptions.RunContinuationsAsynchro
 60262                return releaseTaskCompletionSource;
 63            }
 60264        }
 65
 66        public Task<TOut> WaitForRelease(TIn value = default)
 67        {
 60268            lock (_sync)
 69            {
 60270                _signalTaskCompletionSource.SetResult(value);
 60271                return _releaseTaskCompletionSource.Task.TimeoutAfterDefault();
 72            }
 60273        }
 74    }
 75}