< Summary

Information
Class: IceRpc.Internal.MetricsProtocolConnectionDecorator
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/MetricsProtocolConnectionDecorator.cs
Tag: 275_13775359185
Line coverage
100%
Covered lines: 44
Uncovered lines: 0
Coverable lines: 44
Total lines: 79
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage
100%
Covered methods: 5
Total methods: 5
Method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ConnectAsync()100%22100%
DisposeAsync()100%44100%
InvokeAsync(...)100%11100%
ShutdownAsync()100%11100%
.ctor(...)100%11100%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/MetricsProtocolConnectionDecorator.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using IceRpc.Transports;
 4
 5namespace IceRpc.Internal;
 6
 7/// <summary>Provides a log decorator for protocol connections.</summary>
 8internal class MetricsProtocolConnectionDecorator : IProtocolConnection
 9{
 10    private readonly bool _connectStarted;
 11    private readonly IProtocolConnection _decoratee;
 12    private bool _isConnected;
 13    private bool _isShutdown;
 14    private readonly Metrics _metrics;
 15
 16    public async Task<(TransportConnectionInformation ConnectionInformation, Task ShutdownRequested)> ConnectAsync(
 17        CancellationToken cancellationToken)
 28018    {
 28019        if (!_connectStarted)
 16420        {
 16421            _metrics.ConnectStart();
 16422        }
 23        try
 28024        {
 28025            (TransportConnectionInformation connectionInformation, Task shutdownRequested) =
 28026                await _decoratee.ConnectAsync(cancellationToken).ConfigureAwait(false);
 22927            _metrics.ConnectSuccess();
 22928            _isConnected = true;
 22929            return (connectionInformation, shutdownRequested);
 30        }
 5131        catch
 5132        {
 5133            _metrics.ConnectionFailure();
 5134            throw;
 35        }
 36        finally
 28037        {
 28038            _metrics.ConnectStop();
 28039        }
 22940    }
 41
 42    public async ValueTask DisposeAsync()
 28043    {
 28044        await _decoratee.DisposeAsync().ConfigureAwait(false);
 28045        if (_isConnected)
 22946        {
 22947            if (!_isShutdown)
 14948            {
 49                // shutdown failed or didn't call shutdown at all.
 14950                _metrics.ConnectionFailure();
 14951            }
 22952            _metrics.ConnectionDisconnected();
 22953        }
 28054    }
 55
 56    public Task<IncomingResponse> InvokeAsync(OutgoingRequest request, CancellationToken cancellationToken) =>
 16057        _decoratee.InvokeAsync(request, cancellationToken);
 58
 59    public async Task ShutdownAsync(CancellationToken cancellationToken)
 10160    {
 10161        await _decoratee.ShutdownAsync(cancellationToken).ConfigureAwait(false);
 8062        _isShutdown = true;
 8063    }
 64
 65    /// <summary>A protocol connection decorator to log connection metrics.</summary>
 66    /// <param name="decoratee">The protocol connection decoratee.</param>
 67    /// <param name="metrics">The metrics object used to log the metrics.</param>
 68    /// <param name="connectStarted">Whether or not the ConnectStart events has be already logged. For server connection
 69    /// the event is logged from a separate <see cref="Server.IConnector"/> decorator.</param>
 28070    internal MetricsProtocolConnectionDecorator(
 28071        IProtocolConnection decoratee,
 28072        Metrics metrics,
 28073        bool connectStarted)
 28074    {
 28075        _connectStarted = connectStarted;
 28076        _decoratee = decoratee;
 28077        _metrics = metrics;
 28078    }
 79}