< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.DuplexRequestContext
Assembly: CoreWCF.NetNamedPipe
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetNamedPipe/src/CoreWCF/Channels/DuplexRequestContext.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 20
Coverable lines: 20
Total lines: 83
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%
OnAbort()100%110%
OnCloseAsync(...)100%110%
OnReplyAsync(...)0%220%
OnOperationInvoke()0%440%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetNamedPipe/src/CoreWCF/Channels/DuplexRequestContext.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.Threading;
 5using System.Threading.Tasks;
 6using CoreWCF.Runtime;
 7
 8namespace CoreWCF.Channels
 9{
 10    internal class DuplexRequestContext : RequestContextBase
 11    {
 12        private readonly IDuplexChannel _channel;
 13        private TaskCompletionSource<object> _dispatchInvokedTcs;
 14        private Task _dispatchInvokedTask;
 15
 16        internal DuplexRequestContext(IDuplexChannel channel, Message request, IDefaultCommunicationTimeouts timeouts)
 017            : base(request, timeouts.CloseTimeout, timeouts.SendTimeout)
 18        {
 019            _channel = channel;
 020        }
 21
 22        protected override void OnAbort()
 23        {
 024        }
 25
 26        protected override Task OnCloseAsync(CancellationToken token)
 27        {
 028            return Task.CompletedTask;
 29        }
 30
 31        protected override Task OnReplyAsync(Message message, CancellationToken token)
 32        {
 033            if (message != null)
 34            {
 035                return _channel.SendAsync(message, token);
 36            }
 37
 038            return Task.CompletedTask;
 39        }
 40
 41        public override void OnOperationInvoke()
 42        {
 043            if (_dispatchInvokedTask == null)
 44            {
 045                if (Interlocked.CompareExchange(ref _dispatchInvokedTask, Task.CompletedTask, null) == null)
 46                {
 047                    return;
 48                }
 49            }
 50
 51            Fx.Assert(_dispatchInvokedTcs != null, "A non-null Task should have the associated TCS set");
 052            _dispatchInvokedTcs.TrySetResult(null);
 053        }
 54
 55        // TODO: Switch to ValueTask as in many scenarios this will be completed before being requested;
 56        public Task OperationDispatching
 57        {
 58            get
 59            {
 060                if (_dispatchInvokedTask != null)
 61                {
 062                    return _dispatchInvokedTask;
 63                }
 64
 65                // There's a small race here where we could create a TCS and dispatchInvokedTask is set via OnOperationI
 66                // In this case, we won't use our TCS and it will simply be an unnecessary allocation. As dispatchInvoke
 67                // always set using Interlocked.CompareExchance, we guarantee returning the correct Task;
 68                // Creating with RunContinuationsAsynchronously otherwise the method awaiting the Task will continue exe
 69                // the thread which calls OnOperationInvoke;
 070                _dispatchInvokedTcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronousl
 071                if (Interlocked.CompareExchange(ref _dispatchInvokedTask, _dispatchInvokedTcs.Task, null) == null)
 72                {
 073                    return _dispatchInvokedTcs.Task;
 74                }
 75                else
 76                {
 077                    _dispatchInvokedTcs = null;
 078                    return _dispatchInvokedTask;
 79                }
 80            }
 81        }
 82    }
 83}