Prevents starting a test-run when one is already started.

This commit is contained in:
benbierens 2023-06-29 13:39:05 +02:00
parent 6a5cde2b91
commit caf5de678a
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
3 changed files with 11 additions and 4 deletions

View File

@ -38,7 +38,7 @@ namespace ContinuousTests
overviewLog.Log("Launching test-loop for " + testLoop.Name);
testLoop.Begin();
Thread.Sleep(TimeSpan.FromSeconds(15));
Thread.Sleep(TimeSpan.FromSeconds(5));
}
overviewLog.Log("Finished launching test-loops.");

View File

@ -31,14 +31,14 @@ namespace ContinuousTests
this.handle = handle;
this.cancelToken = cancelToken;
testName = handle.Test.GetType().Name;
fixtureLog = new FixtureLog(new LogConfig(config.LogPath, false), testName);
fixtureLog = new FixtureLog(new LogConfig(config.LogPath, true), testName);
nodes = CreateRandomNodes(handle.Test.RequiredNumberOfNodes);
dataFolder = config.DataPath + "-" + Guid.NewGuid();
fileManager = new FileManager(fixtureLog, CreateFileManagerConfiguration());
}
public void Run()
public void Run(EventWaitHandle runFinishedHandle)
{
taskFactory.Run(() =>
{
@ -47,6 +47,7 @@ namespace ContinuousTests
RunTest();
fileManager.DeleteAllTestFiles();
Directory.Delete(dataFolder, true);
runFinishedHandle.Set();
}
catch (Exception ex)
{

View File

@ -10,6 +10,7 @@ namespace ContinuousTests
private readonly Type testType;
private readonly TimeSpan runsEvery;
private readonly CancellationToken cancelToken;
private readonly EventWaitHandle runFinishedHandle = new EventWaitHandle(true, EventResetMode.ManualReset);
public TestLoop(TaskFactory taskFactory, Configuration config, BaseLog overviewLog, Type testType, TimeSpan runsEvery, CancellationToken cancelToken)
{
@ -32,7 +33,10 @@ namespace ContinuousTests
{
while (true)
{
WaitHandle.WaitAny(new[] { runFinishedHandle, cancelToken.WaitHandle });
cancelToken.ThrowIfCancellationRequested();
StartTest();
cancelToken.WaitHandle.WaitOne(runsEvery);
@ -55,7 +59,9 @@ namespace ContinuousTests
var test = (ContinuousTest)Activator.CreateInstance(testType)!;
var handle = new TestHandle(test);
var run = new SingleTestRun(taskFactory, config, overviewLog, handle, cancelToken);
run.Run();
runFinishedHandle.Reset();
run.Run(runFinishedHandle);
}
}
}