feat(session): share the session directory between instances #33

Merged
benvin merged 11 commits from benvin/session-directory into main 2026-09-27 11:24:32 +10:00
Showing only changes of commit 577d24d190 - Show all commits
@@ -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<IConnectionMultiplexer>();
redis.Setup(i => i.GetDatabase(It.IsAny<int>(), It.IsAny<object>())).Returns(Mock.Of<IDatabase>());
redis.Setup(i => i.GetSubscriber(It.IsAny<object>())).Throws(new RedisConnectionException(ConnectionFailureType.UnableToConnect, "unreachable"));
var services = Build(configured: true, redis.Object);
Assert.IsType<NullSessionDirectory>(services.GetRequiredService<ISessionDirectory>());
Assert.IsType<NullPodMessageBus>(services.GetRequiredService<IPodMessageBus>());
}
private static ServiceProvider Build(bool configured)
private static ServiceProvider Build(bool configured, IConnectionMultiplexer? redis = null)
{
var settings = new Dictionary<string, string?>();
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();
}