mirror of
https://github.com/logos-storage/logos-storage-nim-cs-dist-tests.git
synced 2026-05-07 18:09:36 +00:00
* ci(docker): build dist-tests images * Update to .net 10, kubernetes client 18.0.13 Kubernetes client 18.0.13 is compatible with Kubernetes 1.34.x. The Kubernetes version is selected automatically by kubeadm in docker desktop (v1.34.1). See https://github.com/kubernetes-client/csharp#version-compatibility for a compatibility table. * Updates to support Kubernetes upgrade * bump openapi.yaml to match openapi.yaml in the logos-storage-nim docker image * bump doc to .net 10 * bump docker to .net 10 * Build image with latest tag always Always build an image with a latest tag (as well as a sha commit hash) when there's a push to master * docker image tag as "latest" only when pushing to master * Update docker image to install doctl * Remove doctl install kubeconfig is now created and uses a plain bearer token instead of using doctl as a credential mgr * Rename and remove all instances of Codex * Further remove CodexNetDeployer as it is no longer needed --------- Co-authored-by: Adam Uhlíř <adam@uhlir.dev>
87 lines
2.5 KiB
C#
87 lines
2.5 KiB
C#
using System.Reflection;
|
|
|
|
namespace ContinuousTests
|
|
{
|
|
public class TestHandle
|
|
{
|
|
private readonly List<MethodMoment> moments = new List<MethodMoment>();
|
|
|
|
public TestHandle(ContinuousTest test)
|
|
{
|
|
Test = test;
|
|
|
|
ReflectTestMoments();
|
|
|
|
var testName = test.GetType().Name;
|
|
if (!moments.Any()) throw new Exception($"Test '{testName}' has no moments.");
|
|
if (moments.Count != moments.Select(m => m.Moment).Distinct().Count()) throw new Exception($"Test '{testName}' has duplicate moments");
|
|
}
|
|
|
|
public ContinuousTest Test { get; }
|
|
|
|
public int GetEarliestMoment()
|
|
{
|
|
return moments.Min(m => m.Moment);
|
|
}
|
|
|
|
public int GetLastMoment()
|
|
{
|
|
return moments.Max(m => m.Moment);
|
|
}
|
|
|
|
public int? GetNextMoment(int currentMoment)
|
|
{
|
|
var remainingMoments = moments.Where(m => m.Moment > currentMoment).ToArray();
|
|
if (!remainingMoments.Any()) return null;
|
|
return remainingMoments.Min(m => m.Moment);
|
|
}
|
|
|
|
public void InvokeMoment(int currentMoment, Action<string> beforeInvoke)
|
|
{
|
|
var moment = moments.SingleOrDefault(m => m.Moment == currentMoment);
|
|
if (moment == null) return;
|
|
|
|
lock (MomentLock.Lock)
|
|
{
|
|
beforeInvoke(moment.Method.Name);
|
|
moment.Method.Invoke(Test, Array.Empty<object>());
|
|
}
|
|
}
|
|
|
|
private void ReflectTestMoments()
|
|
{
|
|
var methods = Test.GetType().GetMethods()
|
|
.Where(m => m.GetCustomAttributes(typeof(TestMomentAttribute), false).Length > 0)
|
|
.ToArray();
|
|
|
|
foreach (var method in methods)
|
|
{
|
|
var moment = method.GetCustomAttribute<TestMomentAttribute>();
|
|
if (moment != null && moment.T >= 0)
|
|
{
|
|
moments.Add(new MethodMoment(method, moment.T));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public class MethodMoment
|
|
{
|
|
public MethodMoment(MethodInfo method, int moment)
|
|
{
|
|
Method = method;
|
|
Moment = moment;
|
|
|
|
if (moment < 0) throw new Exception("Moment must be zero or greater.");
|
|
}
|
|
|
|
public MethodInfo Method { get; }
|
|
public int Moment { get; }
|
|
}
|
|
|
|
public static class MomentLock
|
|
{
|
|
public static readonly object Lock = new();
|
|
}
|
|
}
|