< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.SynchronizedMessageSource
Assembly: CoreWCF.Http
File(s): /home/runner/work/CoreWCF/CoreWCF/src/Common/src/DuplexChannels/CoreWCF/Channels/SynchronizedMessageSource.cs
Line coverage
42%
Covered lines: 11
Uncovered lines: 15
Coverable lines: 26
Total lines: 73
Line coverage: 42.3%
Branch coverage
50%
Covered branches: 2
Total branches: 4
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%11100%
WaitForMessageAsync()0%220%
ReceiveAsync()100%2263.63%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/Common/src/DuplexChannels/CoreWCF/Channels/SynchronizedMessageSource.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System;
 5using System.Threading;
 6using System.Threading.Tasks;
 7using CoreWCF;
 8using CoreWCF.Runtime;
 9
 10namespace CoreWCF.Channels
 11{
 12    internal class SynchronizedMessageSource
 13    {
 14        private readonly IMessageSource _source;
 15        private readonly SemaphoreSlim _sourceLock;
 16
 1117        public SynchronizedMessageSource(IMessageSource source)
 18        {
 1119            _source = source;
 1120            _sourceLock = new SemaphoreSlim(1);
 1121        }
 22
 23        public async Task<bool> WaitForMessageAsync(CancellationToken token)
 24        {
 025            bool lockAcquired = false;
 26            try
 27            {
 028                await _sourceLock.WaitAsync(token);
 029                lockAcquired = true;
 030                return await _source.WaitForMessageAsync(token);
 31            }
 032            catch (OperationCanceledException)
 33            {
 34                // TODO: Fix the timeout value reported
 035                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TimeoutException(
 036                                                SR.Format(SR.WaitForMessageTimedOut, TimeSpan.Zero),
 037                                                TimeoutHelper.CreateEnterTimedOutException(TimeSpan.Zero)));
 38            }
 39            finally
 40            {
 041                if (lockAcquired)
 42                {
 043                    _sourceLock.Release();
 44                }
 45            }
 046        }
 47
 48        public async Task<Message> ReceiveAsync(CancellationToken token)
 49        {
 2650            bool lockAcquired = false;
 51            try
 52            {
 2653                await _sourceLock.WaitAsync(token);
 2654                lockAcquired = true;
 2655                return await _source.ReceiveAsync(token);
 56            }
 057            catch (OperationCanceledException)
 58            {
 59                // TODO: Fix the timeout value reported
 060                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TimeoutException(
 061                                                SR.Format(SR.ReceiveTimedOut2, TimeSpan.Zero),
 062                                                TimeoutHelper.CreateEnterTimedOutException(TimeSpan.Zero)));
 63            }
 64            finally
 65            {
 2666                if (lockAcquired)
 67                {
 2668                    _sourceLock.Release();
 69                }
 70            }
 2671        }
 72    }
 73}