diff --git a/tests/Jellyfin.Server.Tests/HighAvailability/SessionDirectoryRegistrationTests.cs b/tests/Jellyfin.Server.Tests/HighAvailability/SessionDirectoryRegistrationTests.cs index 60f7c70d0d..3214ae592a 100644 --- a/tests/Jellyfin.Server.Tests/HighAvailability/SessionDirectoryRegistrationTests.cs +++ b/tests/Jellyfin.Server.Tests/HighAvailability/SessionDirectoryRegistrationTests.cs @@ -5,6 +5,8 @@ using MediaBrowser.Controller.Session; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging.Abstractions; +using Moq; +using StackExchange.Redis; using Xunit; namespace Jellyfin.Server.Tests.HighAvailability; @@ -25,16 +27,21 @@ public static class SessionDirectoryRegistrationTests } [Fact] - public static void AddSessionDirectory_WithAnUnusableRedisConnection_FallsBackOnBothHalves() + public static void AddSessionDirectory_WhenOneHalfCannotBeBuilt_FallsBackOnBoth() { - // The multiplexer is deliberately absent, which is what an unreachable Redis amounts to here. - var services = Build(configured: true); + // A connection that can serve the directory but not the bus: taking the directory on its own + // would advertise every instance's sessions and then fail every command sent to one. + var redis = new Mock(); + redis.Setup(i => i.GetDatabase(It.IsAny(), It.IsAny())).Returns(Mock.Of()); + redis.Setup(i => i.GetSubscriber(It.IsAny())).Throws(new RedisConnectionException(ConnectionFailureType.UnableToConnect, "unreachable")); + + var services = Build(configured: true, redis.Object); Assert.IsType(services.GetRequiredService()); Assert.IsType(services.GetRequiredService()); } - private static ServiceProvider Build(bool configured) + private static ServiceProvider Build(bool configured, IConnectionMultiplexer? redis = null) { var settings = new Dictionary(); if (configured) @@ -43,9 +50,14 @@ public static class SessionDirectoryRegistrationTests } var configuration = new ConfigurationBuilder().AddInMemoryCollection(settings).Build(); + var serviceCollection = new ServiceCollection().AddLogging(); - return new ServiceCollection() - .AddLogging() + if (redis is not null) + { + serviceCollection.AddSingleton(redis); + } + + return serviceCollection .AddSessionDirectory(configuration, NullLogger.Instance) .BuildServiceProvider(); }