Running two client test

This commit is contained in:
benbierens 2023-06-25 10:50:01 +02:00
parent 9a9c740e1c
commit 40b4d8aba3
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
7 changed files with 72 additions and 64 deletions

View File

@ -36,25 +36,22 @@ namespace ContinuousTests
catch { }
}
var logPath = "logs";// Environment.GetEnvironmentVariable("LOGPATH");
var codexDeploymentJson = "C:\\Users\\Ben\\Desktop\\codex-deployment.json"; //Environment.GetEnvironmentVariable("CODEXDEPLOYMENT");
var sleepPerSingle = "10";// Environment.GetEnvironmentVariable("SLEEPSECONDSPERSINGLETEST");
var sleepPerAll = "10";// Environment.GetEnvironmentVariable("SLEEPSECONDSPERALLTESTS");
var keep = ""; // Environment.GetEnvironmentVariable("KEEPPASSEDTESTLOGS");
var logPath = Environment.GetEnvironmentVariable("LOGPATH");
var dataPath = Environment.GetEnvironmentVariable("DATAPATH");
var codexDeploymentJson = Environment.GetEnvironmentVariable("CODEXDEPLOYMENT");
var keep = Environment.GetEnvironmentVariable("KEEPPASSEDTESTLOGS");
if (!string.IsNullOrEmpty(logPath) &&
!string.IsNullOrEmpty(codexDeploymentJson) &&
!string.IsNullOrEmpty(sleepPerSingle) &&
!string.IsNullOrEmpty(sleepPerAll))
!string.IsNullOrEmpty(dataPath) &&
!string.IsNullOrEmpty(codexDeploymentJson))
{
try
{
return new Configuration
{
LogPath = logPath,
DataPath = dataPath,
CodexDeployment = ParseCodexDeploymentJson(codexDeploymentJson),
//SleepSecondsPerSingleTest = Convert.ToInt32(sleepPerSingle),
//SleepSecondsPerAllTests = Convert.ToInt32(sleepPerAll),
KeepPassedTestLogs = keep == "1"
};
}
@ -68,29 +65,21 @@ namespace ContinuousTests
throw new Exception($"Unable to load configuration from '{filename}', and " +
"unable to load configuration from environment variables. " + nl +
"'LOGPATH' = Path where log files will be saved." + nl +
"'DATAPATH' = Path where temporary data files will be saved." + nl +
"'CODEXDEPLOYMENT' = Path to codex-deployment JSON file." + nl +
"'SLEEPSECONDSPERSINGLETEST' = Seconds to sleep after each individual test." + nl +
"'SLEEPSECONDSPERALLTESTS' = Seconds to sleep after all tests, before starting again." + nl +
"'KEEPPASSEDTESTLOGS' = (Optional, default: 0) Set to '1' to keep log files of tests that passed." + nl +
nl);
}
private void Validate(Configuration configuration)
{
//if (configuration.SleepSecondsPerSingleTest < 1)
//{
// Console.WriteLine("Warning: configuration.SleepSecondsPerSingleTest was less than 1 seconds. Using 1 seconds instead!");
// configuration.SleepSecondsPerSingleTest = 1;
//}
//if (configuration.SleepSecondsPerAllTests < 1)
//{
// Console.WriteLine("Warning: configuration.SleepSecondsPerAllTests was less than 10 seconds. Using 10 seconds instead!");
// configuration.SleepSecondsPerAllTests = 10;
//}
if (string.IsNullOrEmpty(configuration.LogPath))
{
throw new Exception($"Unvalid logpath set: '{configuration.LogPath}'");
throw new Exception($"Invalid LogPath set: '{configuration.LogPath}'");
}
if (string.IsNullOrEmpty(configuration.DataPath))
{
throw new Exception($"Invalid DataPath set: '{configuration.DataPath}'");
}
if (configuration.CodexDeployment == null || !configuration.CodexDeployment.CodexContainers.Any())

View File

@ -12,7 +12,9 @@ namespace ContinuousTests
public abstract class ContinuousTest
{
protected const int Zero = 0;
protected const int HourOne = 3600;
protected const int MinuteOne = 60;
protected const int MinuteFive = MinuteOne * 5;
protected const int HourOne = MinuteOne * 60;
protected const int DayOne = HourOne * 24;
protected const int DayThree = DayOne * 3;

View File

@ -25,7 +25,7 @@
t.Begin();
}
Thread.Sleep(TimeSpan.MaxValue);
while (true) Thread.Sleep((2 ^ 31) - 1);
}
}
}

View File

@ -15,6 +15,7 @@ namespace ContinuousTests
private readonly CodexNode[] nodes;
private readonly FileManager fileManager;
private readonly FixtureLog fixtureLog;
private readonly string dataFolder;
public SingleTestRun(Configuration config, TestHandle handle)
{
@ -25,6 +26,7 @@ namespace ContinuousTests
fixtureLog = new FixtureLog(new LogConfig(config.LogPath, false), testName);
nodes = CreateRandomNodes(handle.Test.RequiredNumberOfNodes);
dataFolder = config.DataPath + "-" + Guid.NewGuid();
fileManager = new FileManager(fixtureLog, CreateFileManagerConfiguration());
}
@ -44,16 +46,16 @@ namespace ContinuousTests
fixtureLog.MarkAsFailed();
}
fileManager.DeleteAllTestFiles();
Directory.Delete(dataFolder, true);
});
}
private void RunTest()
{
var earliestMoment = handle.GetEarliestMoment();
var lastMoment = handle.GetLastMoment();
var t = earliestMoment;
while (t <= lastMoment)
while (true)
{
RunMoment(t);
@ -72,11 +74,15 @@ namespace ContinuousTests
}
else
{
Log(" > Completed last test moment. Test ended.");
if (exceptions.Any())
{
Log(" > Completed last test moment. Test failed.");
throw exceptions.First();
}
Log(" > Completed last test moment. Test passed.");
return;
}
}
if (exceptions.Any()) throw exceptions.First();
}
private void RunMoment(int t)
@ -130,7 +136,7 @@ namespace ContinuousTests
private DistTestCore.Configuration CreateFileManagerConfiguration()
{
return new DistTestCore.Configuration(null, string.Empty, false, config.DataPath + Guid.NewGuid(),
return new DistTestCore.Configuration(null, string.Empty, false, dataFolder,
CodexLogLevel.Error, TestRunnerLocation.ExternalToCluster);
}
}

View File

@ -31,7 +31,7 @@ namespace ContinuousTests
public int? GetNextMoment(int currentMoment)
{
var remainingMoments = moments.Where(m => m.Moment >= currentMoment).ToArray();
var remainingMoments = moments.Where(m => m.Moment > currentMoment).ToArray();
if (!remainingMoments.Any()) return null;
return remainingMoments.Min(m => m.Moment);
}
@ -71,6 +71,8 @@ namespace ContinuousTests
{
Method = method;
Moment = moment;
if (moment < 0) throw new Exception("Moment must be zero or greater.");
}
public MethodInfo Method { get; }

View File

@ -2,25 +2,24 @@
namespace ContinuousTests.Tests
{
public class MarketplaceTest : ContinuousTest
{
public override int RequiredNumberOfNodes => 1;
public override TimeSpan RunTestEvery => TimeSpan.FromDays(1);
public override TestFailMode TestFailMode => TestFailMode.AlwaysRunAllMoments;
//public class MarketplaceTest : ContinuousTest
//{
// public override int RequiredNumberOfNodes => 1;
// public override TimeSpan RunTestEvery => TimeSpan.FromDays(1);
// public override TestFailMode TestFailMode => TestFailMode.AlwaysRunAllMoments;
[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: 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()
{
}
}
// [TestMoment(t: DayThree)]
// public void NodeDownloadsStorageRequestData()
// {
// }
//}
}

View File

@ -3,20 +3,30 @@ using NUnit.Framework;
namespace ContinuousTests.Tests
{
//public class TwoClientTest : ContinuousTest
//{
// public override int RequiredNumberOfNodes => 2;
public class TwoClientTest : ContinuousTest
{
public override int RequiredNumberOfNodes => 2;
public override TimeSpan RunTestEvery => TimeSpan.FromHours(1);
public override TestFailMode TestFailMode => TestFailMode.StopAfterFirstFailure;
// public override void Run()
// {
// var file = FileManager.GenerateTestFile(10.MB());
private ContentId? cid;
private TestFile file = null!;
// var cid = UploadFile(Nodes[0], file);
// Assert.That(cid, Is.Not.Null);
[TestMoment(t: Zero)]
public void UploadTestFile()
{
file = FileManager.GenerateTestFile(10.MB());
// var dl = DownloadContent(Nodes[1], cid!);
cid = UploadFile(Nodes[0], file);
Assert.That(cid, Is.Not.Null);
}
// file.AssertIsEqual(dl);
// }
//}
[TestMoment(t: MinuteFive)]
public void DownloadTestFile()
{
var dl = DownloadContent(Nodes[1], cid!);
file.AssertIsEqual(dl);
}
}
}