< Summary

Information
Class: Elsa.Diagnostics.ConsoleLogs.Services.ConsoleLogCaptureShellLease
Assembly: Elsa.Diagnostics.ConsoleLogs
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Diagnostics.ConsoleLogs/Services/ConsoleLogCaptureShellLease.cs
Line coverage
87%
Covered lines: 21
Uncovered lines: 3
Coverable lines: 24
Total lines: 69
Line coverage: 87.5%
Branch coverage
62%
Covered branches: 5
Total branches: 8
Branch coverage: 62.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
StartAsync()66.66%6685.71%
StopAsync()50%2287.5%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Diagnostics.ConsoleLogs/Services/ConsoleLogCaptureShellLease.cs

#LineLine coverage
 1using ConsoleLogStreaming.Core;
 2using ConsoleLogStreaming.Core.Capture;
 3using CShells.Lifecycle;
 4using Microsoft.Extensions.DependencyInjection;
 5
 6namespace Elsa.Diagnostics.ConsoleLogs.Services;
 7
 38public class ConsoleLogCaptureShellLease(IServiceProvider serviceProvider)
 9{
 310    private readonly SemaphoreSlim _lock = new(1, 1);
 11    private bool _started;
 12
 13    public async Task StartAsync(CancellationToken cancellationToken = default)
 14    {
 215        await _lock.WaitAsync(cancellationToken);
 16        try
 17        {
 218            if (_started)
 019                return;
 20
 221            ConsoleLogStreamingHost.AddReference();
 222            var releaseReference = true;
 23
 24            try
 25            {
 226                var capture = serviceProvider.GetRequiredService<IConsoleLogCapture>();
 227                await capture.StartAsync(cancellationToken);
 228                _started = true;
 229                releaseReference = false;
 30            }
 31            finally
 32            {
 233                if (releaseReference)
 034                    await ConsoleLogStreamingHost.ReleaseReferenceAsync(CancellationToken.None);
 35            }
 236        }
 37        finally
 38        {
 239            _lock.Release();
 40        }
 241    }
 42
 43    public async Task StopAsync(CancellationToken cancellationToken = default)
 44    {
 245        await _lock.WaitAsync(cancellationToken);
 46        try
 47        {
 248            if (!_started)
 049                return;
 50
 251            _started = false;
 252            await ConsoleLogStreamingHost.ReleaseReferenceAsync(cancellationToken);
 253        }
 54        finally
 55        {
 256            _lock.Release();
 57        }
 258    }
 59}
 60
 61public class ConsoleLogCaptureShellInitializer(ConsoleLogCaptureShellLease lease) : IShellInitializer
 62{
 63    public Task InitializeAsync(CancellationToken cancellationToken = default) => lease.StartAsync(cancellationToken);
 64}
 65
 66public class ConsoleLogCaptureShellDrainHandler(ConsoleLogCaptureShellLease lease) : IDrainHandler
 67{
 68    public Task DrainAsync(IDrainExtensionHandle extensionHandle, CancellationToken cancellationToken) => lease.StopAsyn
 69}