< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.SynchronizedMessageSource
Assembly: CoreWCF.NetFramingBase
File(s): /home/runner/work/CoreWCF/CoreWCF/src/Common/src/DuplexChannels/CoreWCF/Channels/SynchronizedMessageSource.cs
Line coverage
57%
Covered lines: 15
Uncovered lines: 11
Coverable lines: 26
Total lines: 73
Line coverage: 57.6%
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%22100%

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
 6417        public SynchronizedMessageSource(IMessageSource source)
 18        {
 6419            _source = source;
 6420            _sourceLock = new SemaphoreSlim(1);
 6421        }
 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        {
 14450            bool lockAcquired = false;
 51            try
 52            {
 14453                await _sourceLock.WaitAsync(token);
 14454                lockAcquired = true;
 14455                return await _source.ReceiveAsync(token);
 56            }
 957            catch (OperationCanceledException)
 58            {
 59                // TODO: Fix the timeout value reported
 960                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TimeoutException(
 961                                                SR.Format(SR.ReceiveTimedOut2, TimeSpan.Zero),
 962                                                TimeoutHelper.CreateEnterTimedOutException(TimeSpan.Zero)));
 63            }
 64            finally
 65            {
 14466                if (lockAcquired)
 67                {
 14468                    _sourceLock.Release();
 69                }
 70            }
 13371        }
 72    }
 73}