< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.WebApi.Email.RegistrationQueue
Assembly: ArturRios.Heimdall.WebApi
File(s): /home/runner/work/heimdall-api/heimdall-api/src/Presentation/ArturRios.Heimdall.WebApi/Email/RegistrationQueue.cs
Line coverage
78%
Covered lines: 11
Uncovered lines: 3
Coverable lines: 14
Total lines: 45
Line coverage: 78.5%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage
100%
Covered methods: 3
Fully covered methods: 2
Total methods: 3
Method coverage: 100%
Full method coverage: 66.6%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Reader()100%11100%
TryEnqueue(...)50%3240%

File(s)

/home/runner/work/heimdall-api/heimdall-api/src/Presentation/ArturRios.Heimdall.WebApi/Email/RegistrationQueue.cs

#LineLine coverage
 1using System.Threading.Channels;
 2using ArturRios.Heimdall.Command.Services;
 3
 4namespace ArturRios.Heimdall.WebApi.Email;
 5
 6/// <summary>
 7///     The in-process queue between UC-47's handler and <see cref="RegistrationDispatcher" />. Bounded,
 8///     never blocks the caller. Shaped exactly like <see cref="PasswordRecoveryQueue" />, whose remarks
 9///     explain why it is in memory rather than a response-time floor or a database outbox.
 10/// </summary>
 11/// <remarks>
 12///     Unlike the recovery queue it holds a secret — a password hash and salt — for the seconds a
 13///     request waits. It is never written anywhere, and a restart drops it with the request, which the
 14///     caller simply repeats.
 15/// </remarks>
 89916public sealed class RegistrationQueue(ILogger<RegistrationQueue> logger) : IRegistrationQueue
 17{
 18    /// <summary>Requests held at most while the dispatcher catches up.</summary>
 19    public const int Capacity = 1024;
 20
 89921    private readonly Channel<RegistrationRequest> _channel = Channel.CreateBounded<RegistrationRequest>(
 89922        new BoundedChannelOptions(Capacity)
 89923        {
 89924            // Wait, not one of the Drop modes: see PasswordRecoveryQueue.
 89925            FullMode = BoundedChannelFullMode.Wait,
 89926            SingleReader = true
 89927        });
 28
 29    /// <summary>The dispatcher's end of the queue.</summary>
 89930    public ChannelReader<RegistrationRequest> Reader => _channel.Reader;
 31
 32    public bool TryEnqueue(RegistrationRequest request)
 33    {
 2034        if (_channel.Writer.TryWrite(request))
 35        {
 2036            return true;
 37        }
 38
 39        // No address in the log (NFR-22).
 040        logger.LogWarning(
 041            "The registration queue is full ({Capacity}); a registration request was dropped", Capacity);
 42
 043        return false;
 44    }
 45}