< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.ConnectionReuseHandler
Assembly: CoreWCF.NetFramingBase
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetFramingBase/src/CoreWCF/Channels/ConnectionReuseHandler.cs
Line coverage
93%
Covered lines: 28
Uncovered lines: 2
Coverable lines: 30
Total lines: 89
Line coverage: 93.3%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%11100%
ReuseConnectionAsync()83.33%6692.59%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetFramingBase/src/CoreWCF/Channels/ConnectionReuseHandler.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.Diagnostics;
 6using System.Threading;
 7using System.Threading.Tasks;
 8using CoreWCF.Channels.Framing;
 9using CoreWCF.Runtime;
 10
 11namespace CoreWCF.Channels
 12{
 13    internal class ConnectionReuseHandler : IConnectionReuseHandler
 14    {
 15        private readonly SemaphoreSlim _connectionPoolSemaphore;
 16
 7117        public ConnectionReuseHandler(ConnectionPoolSettings connectionPoolSettings)
 18        {
 7119            _connectionPoolSemaphore = new SemaphoreSlim(connectionPoolSettings.MaxOutboundConnectionsPerEndpoint);
 7120        }
 21
 22        public async Task<bool> ReuseConnectionAsync(FramingConnection connection, CancellationToken cancellationToken)
 23        {
 11024            if (cancellationToken.IsCancellationRequested)
 25            {
 526                return false;
 27            }
 28
 10529            if (!_connectionPoolSemaphore.Wait(0))
 30            {
 31                //if (DiagnosticUtility.ShouldTraceWarning)
 32                //{
 33                //    TraceUtility.TraceEvent(TraceEventType.Warning,
 34                //        TraceCode.ServerMaxPooledConnectionsQuotaReached,
 35                //        SR.GetString(SR.TraceCodeServerMaxPooledConnectionsQuotaReached, maxPooledConnections),
 36                //        new StringTraceRecord("MaxOutboundConnectionsPerEndpoint", maxPooledConnections.ToString(Cultu
 37                //        this, null);
 38                //}
 39
 40                //if (TD.ServerMaxPooledConnectionsQuotaReachedIsEnabled())
 41                //{
 42                //    TD.ServerMaxPooledConnectionsQuotaReached();
 43                //}
 044                connection.Logger.ConnectionPoolFull();
 45                // No space left in the connection pool
 046                return false;
 47            }
 48
 49            try
 50            {
 10551                connection.Reset();
 52
 10553                using (var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(
 10554                    connection.ChannelInitializationCancellationToken,
 10555                    cancellationToken))
 56                {
 10557                    connection.Logger.StartPendingReadOnIdleSocket();
 58                    Debug.Assert(connection.Transport == connection.RawTransport);
 10559                    var readResult = await connection.Input.ReadAsync(linkedCts.Token);
 3760                    connection.Logger.EndPendingReadOnIdleSocket(readResult);
 3761                    if (readResult.IsCompleted)
 62                    {
 163                        connection.Logger.IdleConnectionClosed();
 164                        connection.Output.Complete();
 165                        return false;
 66                    }
 67
 3668                    connection.Input.AdvanceTo(readResult.Buffer.Start); // Don't consume any bytes. The pending read is
 3669                }
 70
 3671                return true;
 72            }
 6773            catch(OperationCanceledException)
 74            {
 6775                connection.Logger.IdleConnectionClosed();
 6776                return false;
 77            }
 178            catch (Exception e)
 79            {
 180                connection.Logger.FailureInConnectionReuse(e);
 181                return false;
 82            }
 83            finally
 84            {
 10585                _connectionPoolSemaphore.Release();
 86            }
 11087        }
 88    }
 89}