< 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: 68
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 CShells.Lifecycle;
 3using Microsoft.Extensions.DependencyInjection;
 4
 5namespace Elsa.Diagnostics.ConsoleLogs.Services;
 6
 37public class ConsoleLogCaptureShellLease(IServiceProvider serviceProvider)
 8{
 39    private readonly SemaphoreSlim _lock = new(1, 1);
 10    private bool _started;
 11
 12    public async Task StartAsync(CancellationToken cancellationToken = default)
 13    {
 214        await _lock.WaitAsync(cancellationToken);
 15        try
 16        {
 217            if (_started)
 018                return;
 19
 220            ConsoleLogStreamingHost.AddReference();
 221            var releaseReference = true;
 22
 23            try
 24            {
 225                var capture = serviceProvider.GetRequiredService<IConsoleLogCapture>();
 226                await capture.StartAsync(cancellationToken);
 227                _started = true;
 228                releaseReference = false;
 29            }
 30            finally
 31            {
 232                if (releaseReference)
 033                    await ConsoleLogStreamingHost.ReleaseReferenceAsync(CancellationToken.None);
 34            }
 235        }
 36        finally
 37        {
 238            _lock.Release();
 39        }
 240    }
 41
 42    public async Task StopAsync(CancellationToken cancellationToken = default)
 43    {
 244        await _lock.WaitAsync(cancellationToken);
 45        try
 46        {
 247            if (!_started)
 048                return;
 49
 250            _started = false;
 251            await ConsoleLogStreamingHost.ReleaseReferenceAsync(cancellationToken);
 252        }
 53        finally
 54        {
 255            _lock.Release();
 56        }
 257    }
 58}
 59
 60public class ConsoleLogCaptureShellInitializer(ConsoleLogCaptureShellLease lease) : IShellInitializer
 61{
 62    public Task InitializeAsync(CancellationToken cancellationToken = default) => lease.StartAsync(cancellationToken);
 63}
 64
 65public class ConsoleLogCaptureShellDrainHandler(ConsoleLogCaptureShellLease lease) : IDrainHandler
 66{
 67    public Task DrainAsync(IDrainExtensionHandle extensionHandle, CancellationToken cancellationToken) => lease.StopAsyn
 68}