From 5930b51e0b82904dba2eed458ea4474f6be83d5d Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Sat, 19 Oct 2024 10:52:54 -0400 Subject: [PATCH] IOptionsMonitor for WindowsByondInstaller --- .../Engine/WindowsByondInstaller.cs | 28 +++++++++---------- .../Live/Instance/EngineTest.cs | 8 +++--- .../Live/Instance/InstanceTest.cs | 5 ++-- tests/Tgstation.Server.Tests/TestVersions.cs | 16 +++++------ 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/Engine/WindowsByondInstaller.cs b/src/Tgstation.Server.Host/Components/Engine/WindowsByondInstaller.cs index ce2c7704e22..971800885f1 100644 --- a/src/Tgstation.Server.Host/Components/Engine/WindowsByondInstaller.cs +++ b/src/Tgstation.Server.Host/Components/Engine/WindowsByondInstaller.cs @@ -77,14 +77,14 @@ sealed class WindowsByondInstaller : ByondInstallerBase, IDisposable readonly IProcessExecutor processExecutor; /// - /// The for the . + /// The for the . /// - readonly GeneralConfiguration generalConfiguration; + readonly IOptionsMonitor generalConfigurationOptions; /// - /// The for the . + /// The for the . /// - readonly SessionConfiguration sessionConfiguration; + readonly IOptionsMonitor sessionConfigurationOptions; /// /// The for the . @@ -100,8 +100,8 @@ sealed class WindowsByondInstaller : ByondInstallerBase, IDisposable /// Initializes a new instance of the class. /// /// The value of . - /// The containing the value of . - /// The containing the value of . + /// The containing the value of . + /// The containing the value of . /// The for the . /// The for the . /// The for the . @@ -109,14 +109,14 @@ public WindowsByondInstaller( IProcessExecutor processExecutor, IIOManager ioManager, IFileDownloader fileDownloader, - IOptions generalConfigurationOptions, - IOptions sessionConfigurationOptions, + IOptionsMonitor generalConfigurationOptions, + IOptionsMonitor sessionConfigurationOptions, ILogger logger) : base(ioManager, logger, fileDownloader) { this.processExecutor = processExecutor ?? throw new ArgumentNullException(nameof(processExecutor)); - generalConfiguration = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions)); - sessionConfiguration = sessionConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(sessionConfigurationOptions)); + this.generalConfigurationOptions = generalConfigurationOptions ?? throw new ArgumentNullException(nameof(generalConfigurationOptions)); + this.sessionConfigurationOptions = sessionConfigurationOptions ?? throw new ArgumentNullException(nameof(sessionConfigurationOptions)); var useServiceSpecialTactics = Environment.Is64BitProcess && Environment.UserName == $"{Environment.MachineName}$"; @@ -150,7 +150,7 @@ public override ValueTask Install(EngineVersion version, string path, bool deplo installDirectXTask, }; - if (!generalConfiguration.SkipAddingByondFirewallException) + if (!generalConfigurationOptions.CurrentValue.SkipAddingByondFirewallException) { var firewallTask = AddDreamDaemonToFirewall(version, path, deploymentPipelineProcesses, cancellationToken); tasks.Add(firewallTask); @@ -165,7 +165,7 @@ public override async ValueTask UpgradeInstallation(EngineVersion version, strin CheckVersionValidity(version); ArgumentNullException.ThrowIfNull(path); - if (generalConfiguration.SkipAddingByondFirewallException) + if (generalConfigurationOptions.CurrentValue.SkipAddingByondFirewallException) return; if (version.Version < DDExeVersion) @@ -224,7 +224,7 @@ public override async ValueTask TrustDmbPath(EngineVersion version, string fullD /// protected override string GetDreamDaemonName(Version byondVersion, out bool supportsCli) { - supportsCli = byondVersion >= DDExeVersion && !sessionConfiguration.ForceUseDreamDaemonExe; + supportsCli = byondVersion >= DDExeVersion && !sessionConfigurationOptions.CurrentValue.ForceUseDreamDaemonExe; return supportsCli ? "dd.exe" : "dreamdaemon.exe"; } @@ -336,7 +336,7 @@ async ValueTask AddDreamDaemonToFirewall(EngineVersion version, string path, boo Logger, ruleName, dreamDaemonPath, - deploymentPipelineProcesses && sessionConfiguration.LowPriorityDeploymentProcesses, + deploymentPipelineProcesses && sessionConfigurationOptions.CurrentValue.LowPriorityDeploymentProcesses, cancellationToken); } catch (Exception ex) diff --git a/tests/Tgstation.Server.Tests/Live/Instance/EngineTest.cs b/tests/Tgstation.Server.Tests/Live/Instance/EngineTest.cs index ffdaeb63e4a..dc19ed91de1 100644 --- a/tests/Tgstation.Server.Tests/Live/Instance/EngineTest.cs +++ b/tests/Tgstation.Server.Tests/Live/Instance/EngineTest.cs @@ -284,10 +284,10 @@ async Task TestNoVersion(CancellationToken cancellationToken) async Task TestCustomInstalls(CancellationToken cancellationToken) { - var generalConfigOptionsMock = new Mock>(); - generalConfigOptionsMock.SetupGet(x => x.Value).Returns(new GeneralConfiguration()); - var sessionConfigOptionsMock = new Mock>(); - sessionConfigOptionsMock.SetupGet(x => x.Value).Returns(new SessionConfiguration()); + var generalConfigOptionsMock = new Mock>(); + generalConfigOptionsMock.SetupGet(x => x.CurrentValue).Returns(new GeneralConfiguration()); + var sessionConfigOptionsMock = new Mock>(); + sessionConfigOptionsMock.SetupGet(x => x.CurrentValue).Returns(new SessionConfiguration()); var assemblyInformationProvider = new AssemblyInformationProvider(); diff --git a/tests/Tgstation.Server.Tests/Live/Instance/InstanceTest.cs b/tests/Tgstation.Server.Tests/Live/Instance/InstanceTest.cs index 76041a375f1..834cfb38370 100644 --- a/tests/Tgstation.Server.Tests/Live/Instance/InstanceTest.cs +++ b/tests/Tgstation.Server.Tests/Live/Instance/InstanceTest.cs @@ -103,6 +103,7 @@ public static async ValueTask DownloadEngineVersion( { OpenDreamGitUrl = openDreamUrl, }; + mockOptions.SetupGet(x => x.CurrentValue).Returns(genConfig); IEngineInstaller byondInstaller = compatVersion.Engine == EngineType.OpenDream @@ -131,8 +132,8 @@ public static async ValueTask DownloadEngineVersion( Mock.Of(), Mock.Of(), fileDownloader, - Options.Create(genConfig), - Options.Create(new SessionConfiguration()), + Mock.Of>(), + Mock.Of>(), Mock.Of>()) : new PosixByondInstaller( Mock.Of(), diff --git a/tests/Tgstation.Server.Tests/TestVersions.cs b/tests/Tgstation.Server.Tests/TestVersions.cs index a0809b78f6c..0f13dd830af 100644 --- a/tests/Tgstation.Server.Tests/TestVersions.cs +++ b/tests/Tgstation.Server.Tests/TestVersions.cs @@ -105,10 +105,10 @@ public void TestApiLibraryVersion() [TestMethod] public async Task TestDDExeByondVersion() { - var mockGeneralConfigurationOptions = new Mock>(); - mockGeneralConfigurationOptions.SetupGet(x => x.Value).Returns(new GeneralConfiguration()); - var mockSessionConfigurationOptions = new Mock>(); - mockSessionConfigurationOptions.SetupGet(x => x.Value).Returns(new SessionConfiguration()); + var mockGeneralConfigurationOptions = new Mock>(); + mockGeneralConfigurationOptions.SetupGet(x => x.CurrentValue).Returns(new GeneralConfiguration()); + var mockSessionConfigurationOptions = new Mock>(); + mockSessionConfigurationOptions.SetupGet(x => x.CurrentValue).Returns(new SessionConfiguration()); using var loggerFactory = LoggerFactory.Create(builder => { @@ -167,13 +167,13 @@ await byondInstaller.DownloadVersion( [TestMethod] public async Task TestMapThreadsByondVersion() { - var mockGeneralConfigurationOptions = new Mock>(); - mockGeneralConfigurationOptions.SetupGet(x => x.Value).Returns(new GeneralConfiguration + var mockGeneralConfigurationOptions = new Mock>(); + mockGeneralConfigurationOptions.SetupGet(x => x.CurrentValue).Returns(new GeneralConfiguration { SkipAddingByondFirewallException = true, }); - var mockSessionConfigurationOptions = new Mock>(); - mockSessionConfigurationOptions.SetupGet(x => x.Value).Returns(new SessionConfiguration()); + var mockSessionConfigurationOptions = new Mock>(); + mockSessionConfigurationOptions.SetupGet(x => x.CurrentValue).Returns(new SessionConfiguration()); using var loggerFactory = LoggerFactory.Create(builder => {