Mode env variables to FrameworkEnvironment

This commit is contained in:
Dan Balasescu
2023-03-06 19:19:25 +09:00
parent eeef6a35d1
commit a5bf178b38
4 changed files with 27 additions and 5 deletions

View File

@@ -0,0 +1,22 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Platform;
namespace osu.Framework
{
public static class FrameworkEnvironment
{
public static readonly ExecutionMode? STARTUP_EXECUTION_MODE;
public static readonly bool NO_TEST_TIMEOUT;
public static readonly bool FORCE_TEST_GC;
static FrameworkEnvironment()
{
STARTUP_EXECUTION_MODE = Enum.TryParse<ExecutionMode>(Environment.GetEnvironmentVariable("OSU_EXECUTION_MODE"), true, out var mode) ? mode : null;
NO_TEST_TIMEOUT = Environment.GetEnvironmentVariable("OSU_TESTS_NO_TIMEOUT") == "1";
FORCE_TEST_GC = Environment.GetEnvironmentVariable("OSU_TESTS_FORCED_GC") == "1";
}
}
}

View File

@@ -52,10 +52,10 @@ namespace osu.Framework.Platform
base.SetupConfig(defaultOverrides);
if (Enum.TryParse<ExecutionMode>(Environment.GetEnvironmentVariable("OSU_EXECUTION_MODE"), out var mode))
if (FrameworkEnvironment.STARTUP_EXECUTION_MODE != null)
{
Config.SetValue(FrameworkSetting.ExecutionMode, mode);
Logger.Log($"Startup execution mode set to {mode} from envvar");
Config.SetValue(FrameworkSetting.ExecutionMode, FrameworkEnvironment.STARTUP_EXECUTION_MODE);
Logger.Log($"Startup execution mode set to {FrameworkEnvironment.STARTUP_EXECUTION_MODE} from envvar");
}
}

View File

@@ -17,7 +17,7 @@ namespace osu.Framework.Testing.Drawables.Steps
private int invocations;
private static readonly int max_attempt_milliseconds = Environment.GetEnvironmentVariable("OSU_TESTS_NO_TIMEOUT") == "1" ? int.MaxValue : 10000;
private static readonly int max_attempt_milliseconds = FrameworkEnvironment.NO_TEST_TIMEOUT ? int.MaxValue : 10000;
public override int RequiredRepetitions => success ? 0 : int.MaxValue;

View File

@@ -470,7 +470,7 @@ namespace osu.Framework.Testing
runner.RunTestBlocking(this);
checkForErrors();
if (Environment.GetEnvironmentVariable("OSU_TESTS_FORCED_GC") == "1")
if (FrameworkEnvironment.FORCE_TEST_GC)
{
// Force any unobserved exceptions to fire against the current test run.
// Without this they could be delayed until a future test scene is running, making tracking down the cause difficult.