2023-06-21 06:28:40 +00:00
|
|
|
|
using DistTestCore;
|
|
|
|
|
using DistTestCore.Codex;
|
|
|
|
|
using Logging;
|
2023-06-21 08:06:54 +00:00
|
|
|
|
using Utils;
|
2023-06-21 06:28:40 +00:00
|
|
|
|
|
|
|
|
|
namespace ContinuousTests
|
|
|
|
|
{
|
2023-06-21 08:06:54 +00:00
|
|
|
|
public class AllTestsRun
|
2023-06-21 06:28:40 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly Configuration config;
|
2023-06-21 08:06:54 +00:00
|
|
|
|
private readonly FixtureLog log;
|
2023-06-21 07:27:59 +00:00
|
|
|
|
private readonly TestFactory testFinder;
|
2023-06-21 06:28:40 +00:00
|
|
|
|
|
2023-06-21 08:06:54 +00:00
|
|
|
|
public AllTestsRun(Configuration config, FixtureLog log, TestFactory testFinder)
|
2023-06-21 06:28:40 +00:00
|
|
|
|
{
|
|
|
|
|
this.config = config;
|
|
|
|
|
this.log = log;
|
|
|
|
|
this.testFinder = testFinder;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 08:06:54 +00:00
|
|
|
|
public ContinuousTestResult RunAll()
|
2023-06-21 06:28:40 +00:00
|
|
|
|
{
|
2023-06-21 07:27:59 +00:00
|
|
|
|
var remainingTests = testFinder.CreateTests().ToList();
|
2023-06-21 08:06:54 +00:00
|
|
|
|
var result = ContinuousTestResult.Passed;
|
2023-06-21 06:28:40 +00:00
|
|
|
|
while (remainingTests.Any())
|
|
|
|
|
{
|
2023-06-21 08:06:54 +00:00
|
|
|
|
var test = remainingTests.PickOneRandom();
|
|
|
|
|
var testLog = log.CreateTestLog(test.Name);
|
|
|
|
|
var singleTestRun = new SingleTestRun(config, test, testLog);
|
2023-06-21 06:28:40 +00:00
|
|
|
|
|
|
|
|
|
log.Log($"Start '{test.Name}'");
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-06-21 08:06:54 +00:00
|
|
|
|
singleTestRun.Run();
|
2023-06-21 06:28:40 +00:00
|
|
|
|
log.Log($"'{test.Name}' = Passed");
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
log.Log($"'{test.Name}' = Failed");
|
2023-06-21 08:06:54 +00:00
|
|
|
|
testLog.MarkAsFailed();
|
|
|
|
|
result = ContinuousTestResult.Failed;
|
2023-06-21 06:28:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Thread.Sleep(config.SleepSecondsPerTest * 1000);
|
|
|
|
|
}
|
2023-06-21 08:06:54 +00:00
|
|
|
|
return result;
|
2023-06-21 06:28:40 +00:00
|
|
|
|
}
|
2023-06-21 08:06:54 +00:00
|
|
|
|
}
|
2023-06-21 06:28:40 +00:00
|
|
|
|
|
2023-06-21 08:06:54 +00:00
|
|
|
|
public class SingleTestRun
|
|
|
|
|
{
|
|
|
|
|
private readonly CodexNodeFactory codexNodeFactory = new CodexNodeFactory();
|
|
|
|
|
private readonly Configuration config;
|
|
|
|
|
private readonly ContinuousTest test;
|
|
|
|
|
private readonly CodexNode[] nodes;
|
|
|
|
|
private readonly FileManager fileManager;
|
|
|
|
|
|
|
|
|
|
public SingleTestRun(Configuration config, ContinuousTest test, BaseLog testLog)
|
2023-06-21 06:28:40 +00:00
|
|
|
|
{
|
2023-06-21 08:06:54 +00:00
|
|
|
|
this.config = config;
|
|
|
|
|
this.test = test;
|
|
|
|
|
|
|
|
|
|
nodes = CreateRandomNodes(test.RequiredNumberOfNodes, testLog);
|
|
|
|
|
fileManager = new FileManager(testLog, new DistTestCore.Configuration());
|
|
|
|
|
|
|
|
|
|
test.Initialize(nodes, testLog, fileManager);
|
2023-06-21 06:28:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 08:06:54 +00:00
|
|
|
|
public void Run()
|
2023-06-21 06:28:40 +00:00
|
|
|
|
{
|
2023-06-21 08:06:54 +00:00
|
|
|
|
test.Run();
|
2023-06-21 06:28:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 08:06:54 +00:00
|
|
|
|
public void TearDown()
|
2023-06-21 06:28:40 +00:00
|
|
|
|
{
|
2023-06-21 08:06:54 +00:00
|
|
|
|
test.Initialize(null!, null!, null!);
|
|
|
|
|
fileManager.DeleteAllTestFiles();
|
2023-06-21 06:28:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 08:06:54 +00:00
|
|
|
|
private CodexNode[] CreateRandomNodes(int number, BaseLog testLog)
|
2023-06-21 07:27:59 +00:00
|
|
|
|
{
|
|
|
|
|
var urls = SelectRandomUrls(number);
|
2023-06-21 08:06:54 +00:00
|
|
|
|
return codexNodeFactory.Create(urls, testLog, test.TimeSet);
|
2023-06-21 07:27:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 08:06:54 +00:00
|
|
|
|
private string[] SelectRandomUrls(int number)
|
2023-06-21 06:28:40 +00:00
|
|
|
|
{
|
2023-06-21 08:06:54 +00:00
|
|
|
|
var urls = config.CodexUrls.ToList();
|
|
|
|
|
var result = new string[number];
|
|
|
|
|
for (var i = 0; i < number; i++)
|
|
|
|
|
{
|
|
|
|
|
result[i] = urls.PickOneRandom();
|
|
|
|
|
}
|
2023-06-21 06:28:40 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|