wip: figuring out log handling for continous tests
This commit is contained in:
parent
9d3874c88f
commit
c08507e1b8
|
@ -18,11 +18,13 @@ namespace ContinuousTests
|
||||||
|
|
||||||
public ContinuousTestResult RunAll()
|
public ContinuousTestResult RunAll()
|
||||||
{
|
{
|
||||||
var remainingTests = testFinder.CreateTests().ToList();
|
var tests = testFinder.CreateTests().ToList();
|
||||||
|
var handles = tests.Select(t => new TestHandle(t)).ToArray();
|
||||||
|
|
||||||
var result = ContinuousTestResult.Passed;
|
var result = ContinuousTestResult.Passed;
|
||||||
while (remainingTests.Any())
|
while (tests.Any())
|
||||||
{
|
{
|
||||||
var test = remainingTests.PickOneRandom();
|
var test = tests.PickOneRandom();
|
||||||
var testLog = log.CreateTestLog(test.Name);
|
var testLog = log.CreateTestLog(test.Name);
|
||||||
var singleTestRun = new SingleTestRun(config, test, testLog);
|
var singleTestRun = new SingleTestRun(config, test, testLog);
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,11 @@ namespace ContinuousTests
|
||||||
|
|
||||||
public abstract class ContinuousTest
|
public abstract class ContinuousTest
|
||||||
{
|
{
|
||||||
|
protected const int Zero = 0;
|
||||||
|
protected const int HourOne = 3600;
|
||||||
|
protected const int DayOne = HourOne * 24;
|
||||||
|
protected const int DayThree = DayOne * 3;
|
||||||
|
|
||||||
private const string UploadFailedMessage = "Unable to store block";
|
private const string UploadFailedMessage = "Unable to store block";
|
||||||
|
|
||||||
public void Initialize(CodexNode[] nodes, BaseLog log, FileManager fileManager)
|
public void Initialize(CodexNode[] nodes, BaseLog log, FileManager fileManager)
|
||||||
|
|
|
@ -4,7 +4,13 @@ using Logging;
|
||||||
|
|
||||||
namespace ContinuousTests
|
namespace ContinuousTests
|
||||||
{
|
{
|
||||||
public class ContinuousTestRunner
|
public interface ITestResultHandler
|
||||||
|
{
|
||||||
|
void TestPassed(ContinuousTest test);
|
||||||
|
void TestFailed(ContinuousTest test);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ContinuousTestRunner : ITestResultHandler
|
||||||
{
|
{
|
||||||
private readonly ConfigLoader configLoader = new ConfigLoader();
|
private readonly ConfigLoader configLoader = new ConfigLoader();
|
||||||
private readonly TestFactory testFactory = new TestFactory();
|
private readonly TestFactory testFactory = new TestFactory();
|
||||||
|
@ -18,12 +24,11 @@ namespace ContinuousTests
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
var log = new FixtureLog(new LogConfig(config.LogPath, false), "ContinuousTestsRun");
|
var log = new FixtureLog(new LogConfig(config.LogPath, false), "ContinuousTestsRun");
|
||||||
var allTestsRun = new AllTestsRun(config, log, testFactory);
|
var allTestsRun = new AllTestsRun(config, log, testFactory, this);
|
||||||
|
|
||||||
var result = ContinuousTestResult.Passed;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
result = allTestsRun.RunAll();
|
allTestsRun.RunAll();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -119,11 +124,15 @@ namespace ContinuousTests
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public enum ContinuousTestResult
|
public void TestPassed(ContinuousTest test)
|
||||||
{
|
{
|
||||||
Passed,
|
throw new NotImplementedException();
|
||||||
Failed
|
}
|
||||||
|
|
||||||
|
public void TestFailed(ContinuousTest test)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace ContinuousTests
|
||||||
|
{
|
||||||
|
public class TestHandle
|
||||||
|
{
|
||||||
|
private readonly List<MethodMoment> moments = new List<MethodMoment>();
|
||||||
|
|
||||||
|
public TestHandle(ContinuousTest test)
|
||||||
|
{
|
||||||
|
Test = test;
|
||||||
|
|
||||||
|
ReflectTestMoments();
|
||||||
|
|
||||||
|
if (!moments.Any()) throw new Exception("Test has no moments.");
|
||||||
|
if (moments.Count != moments.Select(m => m.Moment).Distinct().Count()) throw new Exception("Test has duplicate moments");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContinuousTest Test { get; }
|
||||||
|
|
||||||
|
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 int GetLastMoment()
|
||||||
|
{
|
||||||
|
return moments.Max(m => m.Moment);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InvokeMoment(int currentMoment)
|
||||||
|
{
|
||||||
|
var moment = moments.SingleOrDefault(m => m.Moment == currentMoment);
|
||||||
|
if (moment == null) return;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MethodInfo Method { get; }
|
||||||
|
public int Moment { get; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
namespace ContinuousTests
|
||||||
|
{
|
||||||
|
public class TestMomentAttribute : Attribute
|
||||||
|
{
|
||||||
|
public TestMomentAttribute(int t)
|
||||||
|
{
|
||||||
|
T = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int T { get; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
using DistTestCore.Codex;
|
||||||
|
|
||||||
|
namespace ContinuousTests.Tests
|
||||||
|
{
|
||||||
|
public class MarketplaceTest : ContinuousTest
|
||||||
|
{
|
||||||
|
public override int RequiredNumberOfNodes => 1;
|
||||||
|
|
||||||
|
public override void Run()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMoment(t: Zero)]
|
||||||
|
public void NodePostsStorageRequest()
|
||||||
|
{
|
||||||
|
//var c = new KubernetesWorkflow.WorkflowCreator(Log, new KubernetesWorkflow.Configuration());
|
||||||
|
//var flow = c.CreateWorkflow();
|
||||||
|
//var rc = flow.Start(10, KubernetesWorkflow.Location.Unspecified, new CodexContainerRecipe(), new KubernetesWorkflow.StartupConfig());
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMoment(t: DayThree)]
|
||||||
|
public void NodeDownloadsStorageRequestData()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue