From 3dcbb78204754e7a1ee45dae674a714bebde654d Mon Sep 17 00:00:00 2001 From: benbierens Date: Mon, 2 Oct 2023 11:18:27 +0200 Subject: [PATCH] Prevents multiple continuous tests from running interleaved. --- Tests/CodexContinuousTests/TestLoop.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Tests/CodexContinuousTests/TestLoop.cs b/Tests/CodexContinuousTests/TestLoop.cs index c1002b8..6c1157a 100644 --- a/Tests/CodexContinuousTests/TestLoop.cs +++ b/Tests/CodexContinuousTests/TestLoop.cs @@ -13,6 +13,7 @@ namespace ContinuousTests private readonly StartupChecker startupChecker; private readonly CancellationToken cancelToken; private readonly EventWaitHandle runFinishedHandle = new EventWaitHandle(true, EventResetMode.ManualReset); + private static object testLock = new object(); public TestLoop(EntryPointFactory entryPointFactory, TaskFactory taskFactory, Configuration config, ILog overviewLog, Type testType, TimeSpan runsEvery, StartupChecker startupChecker, CancellationToken cancelToken) { @@ -41,13 +42,19 @@ namespace ContinuousTests NumberOfFailures = 0; while (!cancelToken.IsCancellationRequested) { - WaitHandle.WaitAny(new[] { runFinishedHandle, cancelToken.WaitHandle }); + lock (testLock) + // In the original design, multiple tests are allowed to interleave their test-moments, increasing test through-put. + // Since we're still stabilizing some of the basics, this lock limits us to 1 test run at a time. + { + WaitHandle.WaitAny(new[] { runFinishedHandle, cancelToken.WaitHandle }); - cancelToken.ThrowIfCancellationRequested(); + cancelToken.ThrowIfCancellationRequested(); - StartTest(); + StartTest(); - cancelToken.WaitHandle.WaitOne(runsEvery); + cancelToken.WaitHandle.WaitOne(runsEvery); + } + Thread.Sleep(100); } } catch (OperationCanceledException)