< Summary - Jellyfin

Information
Class: Jellyfin.Server.HealthChecks.DbContextFactoryHealthCheck<T>
Assembly: jellyfin
File(s): /srv/git/jellyfin/Jellyfin.Server/HealthChecks/DbContextFactoryHealthCheck.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 9
Coverable lines: 9
Total lines: 43
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 1/23/2026 - 12:11:06 AM Line coverage: 0% (0/2) Total lines: 434/19/2026 - 12:14:27 AM Line coverage: 0% (0/9) Branch coverage: 0% (0/2) Total lines: 43 4/19/2026 - 12:14:27 AM Line coverage: 0% (0/9) Branch coverage: 0% (0/2) Total lines: 43

Coverage delta

Coverage delta 1 -1

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
CheckHealthAsync()0%620%

File(s)

/srv/git/jellyfin/Jellyfin.Server/HealthChecks/DbContextFactoryHealthCheck.cs

#LineLine coverage
 1using System;
 2using System.Threading;
 3using System.Threading.Tasks;
 4using Microsoft.EntityFrameworkCore;
 5using Microsoft.Extensions.Diagnostics.HealthChecks;
 6
 7namespace Jellyfin.Server.HealthChecks;
 8
 9/// <summary>
 10/// Implementation of the <see cref="DbContextHealthCheck{TContext}"/> for a <see cref="IDbContextFactory{TContext}"/>.
 11/// </summary>
 12/// <typeparam name="TContext">The type of database context.</typeparam>
 13public class DbContextFactoryHealthCheck<TContext> : IHealthCheck
 14    where TContext : DbContext
 15{
 16    private readonly IDbContextFactory<TContext> _dbContextFactory;
 17
 18    /// <summary>
 19    /// Initializes a new instance of the <see cref="DbContextFactoryHealthCheck{TContext}"/> class.
 20    /// </summary>
 21    /// <param name="contextFactory">Instance of the <see cref="IDbContextFactory{TContext}"/> interface.</param>
 22    public DbContextFactoryHealthCheck(IDbContextFactory<TContext> contextFactory)
 23    {
 024        _dbContextFactory = contextFactory;
 025    }
 26
 27    /// <inheritdoc />
 28    public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToke
 29    {
 030        ArgumentNullException.ThrowIfNull(context);
 31
 032        var dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken).ConfigureAwait(false);
 033        await using (dbContext.ConfigureAwait(false))
 34        {
 035            if (await dbContext.Database.CanConnectAsync(cancellationToken).ConfigureAwait(false))
 36            {
 037                return HealthCheckResult.Healthy();
 38            }
 39        }
 40
 041        return HealthCheckResult.Unhealthy();
 042    }
 43}