< Summary

Information
Class: IceRpc.Internal.MetricsProtocolConnectionDecorator
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/MetricsProtocolConnectionDecorator.cs
Tag: 1986_28452893481
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
Fully covered methods: 5
Total methods: 5
Method coverage: 100%
Full 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)
 18418    {
 18419        if (!_connectStarted)
 10420        {
 10421            _metrics.ConnectStart();
 10422        }
 23        try
 18424        {
 18425            (TransportConnectionInformation connectionInformation, Task shutdownRequested) =
 18426                await _decoratee.ConnectAsync(cancellationToken).ConfigureAwait(false);
 16027            _metrics.ConnectSuccess();
 16028            _isConnected = true;
 16029            return (connectionInformation, shutdownRequested);
 30        }
 2431        catch
 2432        {
 2433            _metrics.ConnectionFailure();
 2434            throw;
 35        }
 36        finally
 18437        {
 18438            _metrics.ConnectStop();
 18439        }
 16040    }
 41
 42    public async ValueTask DisposeAsync()
 18443    {
 18444        await _decoratee.DisposeAsync().ConfigureAwait(false);
 18445        if (_isConnected)
 16046        {
 16047            if (!_isShutdown)
 9248            {
 49                // shutdown failed or didn't call shutdown at all.
 9250                _metrics.ConnectionFailure();
 9251            }
 16052            _metrics.ConnectionDisconnected();
 16053        }
 18454    }
 55
 56    public Task<IncomingResponse> InvokeAsync(OutgoingRequest request, CancellationToken cancellationToken) =>
 13457        _decoratee.InvokeAsync(request, cancellationToken);
 58
 59    public async Task ShutdownAsync(CancellationToken cancellationToken)
 8260    {
 8261        await _decoratee.ShutdownAsync(cancellationToken).ConfigureAwait(false);
 6862        _isShutdown = true;
 6863    }
 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>
 18470    internal MetricsProtocolConnectionDecorator(
 18471        IProtocolConnection decoratee,
 18472        Metrics metrics,
 18473        bool connectStarted)
 18474    {
 18475        _connectStarted = connectStarted;
 18476        _decoratee = decoratee;
 18477        _metrics = metrics;
 18478    }
 79}