test(session): prove the directory and bus fall back together
This commit is contained in:
@@ -5,6 +5,8 @@ using MediaBrowser.Controller.Session;
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
using Moq;
|
||||||
|
using StackExchange.Redis;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Jellyfin.Server.Tests.HighAvailability;
|
namespace Jellyfin.Server.Tests.HighAvailability;
|
||||||
@@ -25,16 +27,21 @@ public static class SessionDirectoryRegistrationTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[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.
|
// A connection that can serve the directory but not the bus: taking the directory on its own
|
||||||
var services = Build(configured: true);
|
// 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<NullSessionDirectory>(services.GetRequiredService<ISessionDirectory>());
|
||||||
Assert.IsType<NullPodMessageBus>(services.GetRequiredService<IPodMessageBus>());
|
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?>();
|
var settings = new Dictionary<string, string?>();
|
||||||
if (configured)
|
if (configured)
|
||||||
@@ -43,9 +50,14 @@ public static class SessionDirectoryRegistrationTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
var configuration = new ConfigurationBuilder().AddInMemoryCollection(settings).Build();
|
var configuration = new ConfigurationBuilder().AddInMemoryCollection(settings).Build();
|
||||||
|
var serviceCollection = new ServiceCollection().AddLogging();
|
||||||
|
|
||||||
return new ServiceCollection()
|
if (redis is not null)
|
||||||
.AddLogging()
|
{
|
||||||
|
serviceCollection.AddSingleton(redis);
|
||||||
|
}
|
||||||
|
|
||||||
|
return serviceCollection
|
||||||
.AddSessionDirectory(configuration, NullLogger.Instance)
|
.AddSessionDirectory(configuration, NullLogger.Instance)
|
||||||
.BuildServiceProvider();
|
.BuildServiceProvider();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user