using System.Globalization;
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.Harness;
///
/// The Akka TestKit time-dilation factor for this run, from the AKKA_TEST_TIMEFACTOR environment
/// variable (unset ⇒ 1, Akka's own default).
///
///
///
/// akka.test.timefactor is Akka's sanctioned answer to "this machine is slower than the one
/// the timeouts were sized on": TestKit multiplies every ExpectMsg / ExpectTerminated /
/// AwaitAssert / AwaitCondition / ExpectNoMsg duration by it — explicit
/// durations included (RemainingOrDilated). The Gitea CI leg sets it (#606): the whole
/// solution runs there at once on the CI runner, and a long tail of 2–8 s presence budgets that
/// never fail locally each failed in roughly one run in eight, a different test each time — a
/// distribution, not a defect, exactly the shape Gitea #500 hit inside this assembly alone.
///
///
/// Dilation cannot make a broken assertion pass: a presence wait still fails, just later, and an
/// absence window only gets LONGER (a stronger check). It does not reach Ask timeouts or
/// plain Task.WaitAsync budgets — those are sized from PresenceBudget instead.
///
///
internal static class TestTimeFactor
{
/// The environment variable the CI workflow sets.
public const string EnvironmentVariable = "AKKA_TEST_TIMEFACTOR";
/// The factor in effect: the variable's value when it parses to a number ≥ 1, else 1.
public static double Value { get; } =
double.TryParse(Environment.GetEnvironmentVariable(EnvironmentVariable), NumberStyles.Float,
CultureInfo.InvariantCulture, out var f) && f >= 1 ? f : 1;
/// A HOCON line setting akka.test.timefactor, to append to a test config.
public static string Hocon =>
"\nakka.test.timefactor = " + Value.ToString(CultureInfo.InvariantCulture) + "\n";
}