< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.TransportConnectionManager
Assembly: CoreWCF.NetNamedPipe
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetNamedPipe/src/CoreWCF/Channels/TransportConnectionManager.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 21
Coverable lines: 21
Total lines: 66
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 10
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%110%
GetNewConnectionId()100%110%
AddConnection(...)0%220%
RemoveConnection(...)0%220%
StopTracking(...)0%220%
CloseAllConnectionsAsync()0%440%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetNamedPipe/src/CoreWCF/Channels/TransportConnectionManager.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.Collections.Concurrent;
 6using System.Collections.Generic;
 7using System.Text;
 8using System.Threading;
 9using System.Threading.Tasks;
 10using CoreWCF.Runtime;
 11
 12namespace CoreWCF.Channels
 13{
 14    internal class TransportConnectionManager
 15    {
 016        private long _lastConnectionId = long.MinValue;
 017        private readonly ConcurrentDictionary<long, ConnectionReference> _connectionReferences = new ConcurrentDictionar
 18
 019        public long GetNewConnectionId() => Interlocked.Increment(ref _lastConnectionId);
 20
 21        public void AddConnection(long id, NamedPipeConnection connection)
 22        {
 023            var connectionReference = new ConnectionReference(id, connection, this);
 24
 025            if (!_connectionReferences.TryAdd(id, connectionReference))
 26            {
 027                throw new ArgumentException("Unable to add specified id.", nameof(id));
 28            }
 029        }
 30
 31        public void RemoveConnection(long id)
 32        {
 033            if (!_connectionReferences.TryRemove(id, out _))
 34            {
 035                throw new ArgumentException("No value found for the specified id.", nameof(id));
 36            }
 037        }
 38
 39        // This is only called by the ConnectionManager when the connection reference becomes
 40        // unrooted because the application never completed.
 41        public void StopTracking(long id)
 42        {
 043            if (!_connectionReferences.TryRemove(id, out _))
 44            {
 045                throw new ArgumentException("No value found for the specified id.", nameof(id));
 46            }
 047        }
 48
 49        public async Task<bool> CloseAllConnectionsAsync(CancellationToken token)
 50        {
 051            var closeTasks = new List<Task>();
 52
 053            foreach (var kvp in _connectionReferences)
 54            {
 055                if (kvp.Value.TryGetConnection(out var connection))
 56                {
 057                    connection.RequestClose();
 058                    closeTasks.Add(connection.ExecutionTask);
 59                }
 60            }
 61
 062            var allClosedTask = Task.WhenAll(closeTasks.ToArray());
 063            return await Task.WhenAny(allClosedTask).CancellableAsyncWait(token) == allClosedTask;
 064        }
 65    }
 66}