2025-05-14 15:01:21 +02:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
using System.Reflection;
|
2025-04-25 15:42:13 +02:00
|
|
|
|
using Core;
|
|
|
|
|
|
using Logging;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DistTestCore
|
|
|
|
|
|
{
|
|
|
|
|
|
public class Global
|
|
|
|
|
|
{
|
2026-04-24 12:24:32 +10:00
|
|
|
|
public const string TestNamespacePrefix = "storage-";
|
2026-05-04 17:02:50 +10:00
|
|
|
|
public static readonly string TestResultsFile = Path.Combine(Path.GetTempPath(), "test-results.jsonl");
|
2025-04-25 15:42:13 +02:00
|
|
|
|
public Configuration Configuration { get; } = new Configuration();
|
|
|
|
|
|
|
|
|
|
|
|
public Assembly[] TestAssemblies { get; }
|
|
|
|
|
|
private readonly EntryPoint globalEntryPoint;
|
|
|
|
|
|
private readonly ILog log;
|
|
|
|
|
|
|
|
|
|
|
|
public Global()
|
|
|
|
|
|
{
|
|
|
|
|
|
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
|
|
|
|
|
TestAssemblies = assemblies.Where(a => a.FullName!.ToLowerInvariant().Contains("test")).ToArray();
|
|
|
|
|
|
|
|
|
|
|
|
log = new ConsoleLog();
|
|
|
|
|
|
globalEntryPoint = new EntryPoint(
|
|
|
|
|
|
log,
|
|
|
|
|
|
Configuration.GetK8sConfiguration(
|
|
|
|
|
|
new DefaultK8sTimeSet(),
|
|
|
|
|
|
TestNamespacePrefix
|
|
|
|
|
|
),
|
|
|
|
|
|
Configuration.GetFileManagerFolder()
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Setup()
|
|
|
|
|
|
{
|
2026-05-04 17:02:50 +10:00
|
|
|
|
// At process exit, write accumulated test-result JSON lines to stdout.
|
|
|
|
|
|
// ProcessExit fires after NUnit is completely done (no more output capture),
|
|
|
|
|
|
// so writes here go directly to the real stdout pipe and appear in Cloud Logging.
|
|
|
|
|
|
AppDomain.CurrentDomain.ProcessExit += (_, _) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!File.Exists(TestResultsFile)) return;
|
|
|
|
|
|
var raw = new StreamWriter(Console.OpenStandardOutput(), leaveOpen: true) { AutoFlush = true };
|
|
|
|
|
|
raw.Write(File.ReadAllText(TestResultsFile));
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-04-30 15:53:14 +10:00
|
|
|
|
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
|
|
|
|
|
|
|
2025-04-25 15:42:13 +02:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2025-05-14 15:01:21 +02:00
|
|
|
|
Trace.Listeners.Add(new ConsoleTraceListener());
|
|
|
|
|
|
|
|
|
|
|
|
Logging.Stopwatch.Measure(log, "Global setup", () =>
|
2025-04-25 15:42:13 +02:00
|
|
|
|
{
|
|
|
|
|
|
globalEntryPoint.Announce();
|
|
|
|
|
|
globalEntryPoint.Tools.CreateWorkflow().DeleteNamespacesStartingWith(TestNamespacePrefix, wait: true);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
GlobalTestFailure.HasFailed = true;
|
|
|
|
|
|
log.Error($"Global setup cleanup failed with: {ex}");
|
2026-05-01 11:07:34 +10:00
|
|
|
|
// Write directly to raw stderr so this is visible even when NUnit
|
|
|
|
|
|
// captures Console.Out/Console.Error for the fixture setup context.
|
|
|
|
|
|
using var err = new StreamWriter(Console.OpenStandardError(), leaveOpen: true) { AutoFlush = true };
|
|
|
|
|
|
err.WriteLine($"[global-setup-failure] {ex}");
|
2025-04-25 15:42:13 +02:00
|
|
|
|
throw;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void TearDown()
|
|
|
|
|
|
{
|
|
|
|
|
|
globalEntryPoint.Decommission(
|
|
|
|
|
|
// There shouldn't be any of either, but clean everything up regardless.
|
|
|
|
|
|
deleteKubernetesResources: true,
|
|
|
|
|
|
deleteTrackedFiles: true,
|
|
|
|
|
|
waitTillDone: true
|
|
|
|
|
|
);
|
2025-05-14 15:01:21 +02:00
|
|
|
|
|
|
|
|
|
|
Trace.Flush();
|
2025-04-25 15:42:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|