Skip to content

Commit

Permalink
Add unit test triggering the issue
Browse files Browse the repository at this point in the history
  • Loading branch information
alnlarsen committed Apr 29, 2024
1 parent 8dc0adc commit e0e6276
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Engine.UnitTests/ResultListeners/PlanRunCollectorListener.cs
Expand Up @@ -13,6 +13,8 @@ public class PlanRunCollectorListener : ResultListener
public List<TestPlanRun> PlanRuns = new List<TestPlanRun>();
[XmlIgnore]
public List<TestStepRun> StepRuns = new List<TestStepRun>();
[XmlIgnore]
public List<TestStepRun> StepRunStartEvents = new List<TestStepRun>();

public string LogString;

Expand All @@ -30,6 +32,7 @@ public override void OnTestPlanRunCompleted(TestPlanRun planRun, System.IO.Strea

public override void OnTestStepRunStart(TestStepRun stepRun)
{
StepRunStartEvents.Add(stepRun);
base.OnTestStepRunStart(stepRun);
}

Expand Down
32 changes: 32 additions & 0 deletions Engine.UnitTests/Results2.cs
Expand Up @@ -4,6 +4,7 @@
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
using OpenTap.Engine.UnitTests;
using OpenTap.Plugins.BasicSteps;

namespace OpenTap.UnitTests
Expand Down Expand Up @@ -125,5 +126,36 @@ public void TestSetParameterRaceCondition(int threadCount, int paramsPerThread)
Assert.AreEqual(param, i);
}
}

class ParameterAssigningResultListener : ResultListener
{
public List<string> Assignments = new List<string>();
public override void OnTestStepRunStart(TestStepRun stepRun)
{
base.OnTestStepRunStart(stepRun);
foreach (var assignment in Assignments)
{
stepRun.Parameters[assignment] = assignment;
}
}
}

[Test]
public void TestRacyResultListeners()
{
using var session = Session.Create(SessionOptions.OverlayComponentSettings);
var collector = new PlanRunCollectorListener();
var a1 = new ParameterAssigningResultListener() { Assignments = { "Param1", "Param2", "Param3" } };
var a2 = new ParameterAssigningResultListener() { Assignments = { "Param4", "Param5", "Param6" } };
ResultSettings.Current.Add(a1);
ResultSettings.Current.Add(a2);
ResultSettings.Current.Add(collector);

var plan = new TestPlan();
plan.ChildTestSteps.Add(new DelayStep());
plan.Execute();

Assert.AreEqual(collector.StepRunStartEvents[0].Verdict, Verdict.NotSet);
}
}
}

0 comments on commit e0e6276

Please sign in to comment.