using System.Globalization;
namespace Chronos.Testing;
///
/// Time budgets of timed tests. CHRONOS_TEST_TIME_FACTOR (at least 1, default 1) stretches them on a CI runner
/// that shares its CPU and disks with other services (the Gitea runner on the owner's server, amended 2026-10-23, R3);
/// on a development PC the budgets apply as written, and the performance gates of perf.yml never set it.
///
public static class TestTiming
{
public const string Variable = "CHRONOS_TEST_TIME_FACTOR";
/// The factor from ; 1 when unset, unreadable or below 1.
public static double Factor { get; } = Parse(Environment.GetEnvironmentVariable(Variable));
/// stretched by .
public static double Budget(double seconds) => seconds * Factor;
/// The factor a value of gives.
public static double Parse(string? value) =>
double.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out var factor) && factor >= 1 && double.IsFinite(factor) ? factor : 1;
}