Skip to content

Commit

Permalink
IOptionsMonitor for WindowsByondInstaller
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Oct 19, 2024
1 parent 94e0e56 commit 5930b51
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ sealed class WindowsByondInstaller : ByondInstallerBase, IDisposable
readonly IProcessExecutor processExecutor;

/// <summary>
/// The <see cref="GeneralConfiguration"/> for the <see cref="WindowsByondInstaller"/>.
/// The <see cref="GeneralConfiguration"/> <see cref="IOptionsMonitor{TOptions}"/> for the <see cref="WindowsByondInstaller"/>.
/// </summary>
readonly GeneralConfiguration generalConfiguration;
readonly IOptionsMonitor<GeneralConfiguration> generalConfigurationOptions;

/// <summary>
/// The <see cref="SessionConfiguration"/> for the <see cref="WindowsByondInstaller"/>.
/// The <see cref="SessionConfiguration"/> <see cref="IOptionsMonitor{TOptions}"/> for the <see cref="WindowsByondInstaller"/>.
/// </summary>
readonly SessionConfiguration sessionConfiguration;
readonly IOptionsMonitor<SessionConfiguration> sessionConfigurationOptions;

/// <summary>
/// The <see cref="SemaphoreSlim"/> for the <see cref="WindowsByondInstaller"/>.
Expand All @@ -100,23 +100,23 @@ sealed class WindowsByondInstaller : ByondInstallerBase, IDisposable
/// Initializes a new instance of the <see cref="WindowsByondInstaller"/> class.
/// </summary>
/// <param name="processExecutor">The value of <see cref="processExecutor"/>.</param>
/// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="generalConfiguration"/>.</param>
/// <param name="sessionConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="sessionConfiguration"/>.</param>
/// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="generalConfigurationOptions"/>.</param>
/// <param name="sessionConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="sessionConfigurationOptions"/>.</param>
/// <param name="ioManager">The <see cref="IIOManager"/> for the <see cref="ByondInstallerBase"/>.</param>
/// <param name="fileDownloader">The <see cref="IFileDownloader"/> for the <see cref="ByondInstallerBase"/>.</param>
/// <param name="logger">The <see cref="ILogger"/> for the <see cref="ByondInstallerBase"/>.</param>
public WindowsByondInstaller(
IProcessExecutor processExecutor,
IIOManager ioManager,
IFileDownloader fileDownloader,
IOptions<GeneralConfiguration> generalConfigurationOptions,
IOptions<SessionConfiguration> sessionConfigurationOptions,
IOptionsMonitor<GeneralConfiguration> generalConfigurationOptions,
IOptionsMonitor<SessionConfiguration> sessionConfigurationOptions,
ILogger<WindowsByondInstaller> 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}$";

Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -224,7 +224,7 @@ public override async ValueTask TrustDmbPath(EngineVersion version, string fullD
/// <inheritdoc />
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";
}

Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions tests/Tgstation.Server.Tests/Live/Instance/EngineTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,10 @@ async Task TestNoVersion(CancellationToken cancellationToken)

async Task TestCustomInstalls(CancellationToken cancellationToken)
{
var generalConfigOptionsMock = new Mock<IOptions<GeneralConfiguration>>();
generalConfigOptionsMock.SetupGet(x => x.Value).Returns(new GeneralConfiguration());
var sessionConfigOptionsMock = new Mock<IOptions<SessionConfiguration>>();
sessionConfigOptionsMock.SetupGet(x => x.Value).Returns(new SessionConfiguration());
var generalConfigOptionsMock = new Mock<IOptionsMonitor<GeneralConfiguration>>();
generalConfigOptionsMock.SetupGet(x => x.CurrentValue).Returns(new GeneralConfiguration());
var sessionConfigOptionsMock = new Mock<IOptionsMonitor<SessionConfiguration>>();
sessionConfigOptionsMock.SetupGet(x => x.CurrentValue).Returns(new SessionConfiguration());

var assemblyInformationProvider = new AssemblyInformationProvider();

Expand Down
5 changes: 3 additions & 2 deletions tests/Tgstation.Server.Tests/Live/Instance/InstanceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public static async ValueTask<IEngineInstallationData> DownloadEngineVersion(
{
OpenDreamGitUrl = openDreamUrl,
};

mockOptions.SetupGet(x => x.CurrentValue).Returns(genConfig);
IEngineInstaller byondInstaller =
compatVersion.Engine == EngineType.OpenDream
Expand Down Expand Up @@ -131,8 +132,8 @@ public static async ValueTask<IEngineInstallationData> DownloadEngineVersion(
Mock.Of<IProcessExecutor>(),
Mock.Of<IIOManager>(),
fileDownloader,
Options.Create(genConfig),
Options.Create(new SessionConfiguration()),
Mock.Of<IOptionsMonitor<GeneralConfiguration>>(),
Mock.Of<IOptionsMonitor<SessionConfiguration>>(),
Mock.Of<ILogger<WindowsByondInstaller>>())
: new PosixByondInstaller(
Mock.Of<IPostWriteHandler>(),
Expand Down
16 changes: 8 additions & 8 deletions tests/Tgstation.Server.Tests/TestVersions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ public void TestApiLibraryVersion()
[TestMethod]
public async Task TestDDExeByondVersion()
{
var mockGeneralConfigurationOptions = new Mock<IOptions<GeneralConfiguration>>();
mockGeneralConfigurationOptions.SetupGet(x => x.Value).Returns(new GeneralConfiguration());
var mockSessionConfigurationOptions = new Mock<IOptions<SessionConfiguration>>();
mockSessionConfigurationOptions.SetupGet(x => x.Value).Returns(new SessionConfiguration());
var mockGeneralConfigurationOptions = new Mock<IOptionsMonitor<GeneralConfiguration>>();
mockGeneralConfigurationOptions.SetupGet(x => x.CurrentValue).Returns(new GeneralConfiguration());
var mockSessionConfigurationOptions = new Mock<IOptionsMonitor<SessionConfiguration>>();
mockSessionConfigurationOptions.SetupGet(x => x.CurrentValue).Returns(new SessionConfiguration());

using var loggerFactory = LoggerFactory.Create(builder =>
{
Expand Down Expand Up @@ -167,13 +167,13 @@ await byondInstaller.DownloadVersion(
[TestMethod]
public async Task TestMapThreadsByondVersion()
{
var mockGeneralConfigurationOptions = new Mock<IOptions<GeneralConfiguration>>();
mockGeneralConfigurationOptions.SetupGet(x => x.Value).Returns(new GeneralConfiguration
var mockGeneralConfigurationOptions = new Mock<IOptionsMonitor<GeneralConfiguration>>();
mockGeneralConfigurationOptions.SetupGet(x => x.CurrentValue).Returns(new GeneralConfiguration
{
SkipAddingByondFirewallException = true,
});
var mockSessionConfigurationOptions = new Mock<IOptions<SessionConfiguration>>();
mockSessionConfigurationOptions.SetupGet(x => x.Value).Returns(new SessionConfiguration());
var mockSessionConfigurationOptions = new Mock<IOptionsMonitor<SessionConfiguration>>();
mockSessionConfigurationOptions.SetupGet(x => x.CurrentValue).Returns(new SessionConfiguration());

using var loggerFactory = LoggerFactory.Create(builder =>
{
Expand Down

0 comments on commit 5930b51

Please sign in to comment.