< Summary

Information
Class: IceRpc.Internal.MetricsProtocolConnectionDecorator
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/MetricsProtocolConnectionDecorator.cs
Tag: 592_20856082467
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)
 15818    {
 15819        if (!_connectStarted)
 9120        {
 9121            _metrics.ConnectStart();
 9122        }
 23        try
 15824        {
 15825            (TransportConnectionInformation connectionInformation, Task shutdownRequested) =
 15826                await _decoratee.ConnectAsync(cancellationToken).ConfigureAwait(false);
 13227            _metrics.ConnectSuccess();
 13228            _isConnected = true;
 13229            return (connectionInformation, shutdownRequested);
 30        }
 2631        catch
 2632        {
 2633            _metrics.ConnectionFailure();
 2634            throw;
 35        }
 36        finally
 15837        {
 15838            _metrics.ConnectStop();
 15839        }
 13240    }
 41
 42    public async ValueTask DisposeAsync()
 15843    {
 15844        await _decoratee.DisposeAsync().ConfigureAwait(false);
 15845        if (_isConnected)
 13246        {
 13247            if (!_isShutdown)
 8248            {
 49                // shutdown failed or didn't call shutdown at all.
 8250                _metrics.ConnectionFailure();
 8251            }
 13252            _metrics.ConnectionDisconnected();
 13253        }
 15854    }
 55
 56    public Task<IncomingResponse> InvokeAsync(OutgoingRequest request, CancellationToken cancellationToken) =>
 13057        _decoratee.InvokeAsync(request, cancellationToken);
 58
 59    public async Task ShutdownAsync(CancellationToken cancellationToken)
 6260    {
 6261        await _decoratee.ShutdownAsync(cancellationToken).ConfigureAwait(false);
 5062        _isShutdown = true;
 5063    }
 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>
 15870    internal MetricsProtocolConnectionDecorator(
 15871        IProtocolConnection decoratee,
 15872        Metrics metrics,
 15873        bool connectStarted)
 15874    {
 15875        _connectStarted = connectStarted;
 15876        _decoratee = decoratee;
 15877        _metrics = metrics;
 15878    }
 79}