The Free Software Media System - Server Backend & API
Make sure logger factories are disposed during integration tests
Mark Monteiroea82e2158c6f
diff --git a/tests/MediaBrowser.Api.Tests/JellyfinApplicationFactory.cs b/tests/MediaBrowser.Api.Tests/JellyfinApplicationFactory.csindex 5300d36610..558539761d 100644--- a/tests/MediaBrowser.Api.Tests/JellyfinApplicationFactory.cs+++ b/tests/MediaBrowser.Api.Tests/JellyfinApplicationFactory.cs@@ -1,3 +1,4 @@+using System;using System.Collections.Concurrent;using System.IO;using Emby.Server.Implementations;@@ -22,7 +23,7 @@ namespace MediaBrowser.Api.Testspublic class JellyfinApplicationFactory : WebApplicationFactory<Startup>{private static readonly string _testPathRoot = Path.Combine(Path.GetTempPath(), "jellyfin-test-data");- private static readonly ConcurrentBag<ApplicationHost> _appHosts = new ConcurrentBag<ApplicationHost>();+ private static readonly ConcurrentBag<IDisposable> _disposableComponents = new ConcurrentBag<IDisposable>();/// <summary>/// Initializes a new instance of <see cref="JellyfinApplicationFactory"/>.@@ -70,15 +71,17 @@ namespace MediaBrowser.Api.Tests// Create a copy of the application configuration to use for startupvar startupConfig = Program.CreateAppConfiguration(commandLineOpts, appPaths);- // Create the app host and initialize itILoggerFactory loggerFactory = new SerilogLoggerFactory();+ _disposableComponents.Add(loggerFactory);++ // Create the app host and initialize itvar appHost = new CoreAppHost(appPaths,loggerFactory,commandLineOpts,new ManagedFileSystem(loggerFactory.CreateLogger<ManagedFileSystem>(), appPaths),new NetworkManager(loggerFactory.CreateLogger<NetworkManager>()));- _appHosts.Add(appHost);+ _disposableComponents.Add(appHost);var serviceCollection = new ServiceCollection();appHost.Init(serviceCollection);@@ -104,12 +107,12 @@ namespace MediaBrowser.Api.Tests/// <inheritdoc/>protected override void Dispose(bool disposing){- foreach (var host in _appHosts)+ foreach (var disposable in _disposableComponents){- host.Dispose();+ disposable.Dispose();}- _appHosts.Clear();+ _disposableComponents.Clear();base.Dispose(disposing);}