Skip to content

Commit

Permalink
Merge pull request #996 from TestCentric/issue-993
Browse files Browse the repository at this point in the history
Ensure that agents exit cleanly
  • Loading branch information
CharliePoole authored Sep 2, 2023
2 parents 418bb22 + 7fa8db2 commit 44186b1
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 24 deletions.
22 changes: 14 additions & 8 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ static string[] VALID_CONFIGS = new [] { "Release", "Debug" };
// NOTE: This must match what is actually referenced by
// the GUI test model project. Hopefully, this is a temporary
// fix, which we can get rid of in the future.
const string REF_ENGINE_VERSION = "2.0.0-beta1";
const string REF_ENGINE_VERSION = "2.0.0-dev00032";

// We must use the latest versions of the pre-installed agents
// which use the engine version specified above.
const string NET462_AGENT_VERSION = "2.1.0-dev00016";
const string NET60_AGENT_VERSION = "2.1.0-dev00022";
const string NET70_AGENT_VERSION = "2.1.0-dev00012";

const string PACKAGE_NAME = "testcentric-gui";
const string NUGET_PACKAGE_NAME = "TestCentric.GuiRunner";
Expand All @@ -20,7 +26,7 @@ const string GUI_RUNNER = "testcentric.exe";
const string GUI_TESTS = "*.Tests.dll";

// Load the recipe
#load nuget:?package=TestCentric.Cake.Recipe&version=1.0.1-dev00043
#load nuget:?package=TestCentric.Cake.Recipe&version=1.0.1-dev00044
// Comment out above line and uncomment below for local tests of recipe changes
//#load ../TestCentric.Cake.Recipe/recipe/*.cake

Expand Down Expand Up @@ -95,9 +101,9 @@ var nugetPackage = new NuGetPackage(
new DirectoryContent("tools/Images/Tree/Visual Studio").WithFiles(
"Images/Tree/Visual Studio/Success.png", "Images/Tree/Visual Studio/Failure.png", "Images/Tree/Visual Studio/Ignored.png", "Images/Tree/Visual Studio/Inconclusive.png", "Images/Tree/Visual Studio/Skipped.png") )
.WithDependencies(
new PackageReference("NUnit.Extension.Net462PluggableAgent", "2.0.1"),
new PackageReference("NUnit.Extension.Net60PluggableAgent", "2.0.0"),
new PackageReference("NUnit.Extension.Net70PluggableAgent", "2.0.0")
new PackageReference("NUnit.Extension.Net462PluggableAgent", NET462_AGENT_VERSION),
new PackageReference("NUnit.Extension.Net60PluggableAgent", NET60_AGENT_VERSION),
new PackageReference("NUnit.Extension.Net70PluggableAgent", NET70_AGENT_VERSION)
),
testRunner: new GuiSelfTester(BuildSettings.NuGetTestDirectory + "TestCentric.GuiRunner/tools/testcentric.exe"),
checks: new PackageCheck[] {
Expand Down Expand Up @@ -137,9 +143,9 @@ var chocolateyPackage = new ChocolateyPackage(
new DirectoryContent("tools/Images/Tree/Visual Studio").WithFiles(
"Images/Tree/Visual Studio/Success.png", "Images/Tree/Visual Studio/Failure.png", "Images/Tree/Visual Studio/Ignored.png", "Images/Tree/Visual Studio/Inconclusive.png", "Images/Tree/Visual Studio/Skipped.png") )
.WithDependencies(
new PackageReference("nunit-extension-net462-pluggable-agent", "2.0.1"),
new PackageReference("nunit-extension-net60-pluggable-agent", "2.0.0"),
new PackageReference("nunit-extension-net70-pluggable-agent", "2.0.0")
new PackageReference("nunit-extension-net462-pluggable-agent", NET462_AGENT_VERSION),
new PackageReference("nunit-extension-net60-pluggable-agent", NET60_AGENT_VERSION),
new PackageReference("nunit-extension-net70-pluggable-agent", NET70_AGENT_VERSION)
),
testRunner: new GuiSelfTester(BuildSettings.ChocolateyTestDirectory + "testcentric-gui/tools/testcentric.exe"),
checks: new PackageCheck[] {
Expand Down
12 changes: 5 additions & 7 deletions package-tests.cake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static void DefinePackageTests()
// Tests of single assemblies targeting each runtime we support

PackageTests.Add(new PackageTest(1, "Net462Test", "Run net462 mock-assembly.dll under .NET 4.6.2",
"net462/mock-assembly.dll",
"net462/mock-assembly.dll --trace:Debug",
MockAssemblyExpectedResult("Net462AgentLauncher")));

PackageTests.Add(new PackageTest(1, "Net35Test", "Run net35 mock-assembly.dll under .NET 4.6.2",
Expand Down Expand Up @@ -110,17 +110,15 @@ public static void DefinePackageTests()
// Multiple assembly tests

PackageTests.Add(new PackageTest(1, "Net462PlusNet35Test", "Run net462 and net35 builds of mock-assembly.dll together",
"net462/mock-assembly.dll net35/mock-assembly.dll",
"net462/mock-assembly.dll net35/mock-assembly.dll --trace:Debug",
MockAssemblyExpectedResult("Net462AgentLauncher", "Net462AgentLauncher")));

PackageTests.Add(new PackageTest(1, "Net462PlusNet60Test", "Run different builds of mock-assembly.dll together",
"net462/mock-assembly.dll net6.0/mock-assembly.dll",
MockAssemblyExpectedResult("Net462AgentLauncher", "Net60AgentLauncher")));

// Level 2 tests are run for PRs and when packages will be published

// TODO: Suppress V2 tests until driver is working
//PackageTests.Add(new PackageTest(2, "NUnitV2Test", "Run mock-assembly.dll built for NUnit V2",
//PackageTests.Add(new PackageTest(1, "NUnitV2Test", "Run mock-assembly.dll built for NUnit V2",
// "v2-tests/mock-assembly.dll",
// new ExpectedResult("Failed")
// {
Expand All @@ -138,8 +136,8 @@ public static void DefinePackageTests()
// first in the project file.
if (BuildSettings.Configuration == "Release")
{
PackageTests.Add(new PackageTest(2, "NUnitProjectTest", "Run an NUnit project",
"../../TestProject.nunit",
PackageTests.Add(new PackageTest(1, "NUnitProjectTest", "Run an NUnit project",
"../../TestProject.nunit --trace:Debug",
MockAssemblyExpectedResult(
"Net462AgentLauncher", "Net462AgentLauncher", "Net60AgentLauncher", "Net60AgentLauncher"),
NUnitProjectLoader));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ private void WireUpEvents()
// Separate internal method for testing
void OnRunFinished(ResultNode result)
{
log.Debug("Test run complete");
OnLongRunningOperationComplete();

UpdateViewCommands();
Expand Down Expand Up @@ -274,7 +275,10 @@ void OnRunFinished(ResultNode result)
// Load test specified on command line or
// the most recent one if options call for it
if (_options.InputFiles.Count != 0)
{
log.Debug($"Loading files from command-line: {string.Join(", ", _options.InputFiles.ToArray())}");
LoadTests(_options.InputFiles);
}
else if (_settings.Gui.LoadLastProject && !_options.NoLoad)
{
foreach (string entry in _recentFiles.Entries)
Expand All @@ -300,7 +304,10 @@ void OnRunFinished(ResultNode result)

// Run loaded test automatically if called for
if (_model.IsPackageLoaded && _options.RunAllTests)
{
log.Debug("Running all tests");
_model.RunTests(_model.LoadedTests);
}
// Currently, --unattended without --run does nothing except exit.
else if (_options.Unattended)
_view.Close();
Expand Down
4 changes: 2 additions & 2 deletions src/TestModel/model/TestCentric.Gui.Model.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<ItemGroup>
<PackageReference Include="Mono.Options" Version="6.12.0.148" />
<PackageReference Include="NUnit.Engine.Api" Version="3.16.2" />
<PackageReference Include="TestCentric.Engine.Api" Version="2.0.0-beta1" />
<PackageReference Include="TestCentric.Engine" Version="2.0.0-beta1" />
<PackageReference Include="TestCentric.Engine.Api" Version="2.0.0-dev00032" />
<PackageReference Include="TestCentric.Engine" Version="2.0.0-dev00032" />
</ItemGroup>

</Project>
21 changes: 17 additions & 4 deletions src/TestModel/model/TestEventDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace TestCentric.Gui.Model
{
public class TestEventDispatcher : ITestEvents, ITestEventListener
{
private static Logger log = InternalTrace.GetLogger("TestEventDispatcher");

private TestModel _model;

private Dictionary<string, ProjectInfo> _projectLookup;
Expand Down Expand Up @@ -129,6 +131,7 @@ public void FireCategorySelectionChanged()
public void OnTestEvent(string report)
{
XmlNode xmlNode = XmlHelper.CreateXmlNode(report);
log.Debug($"Received event {xmlNode.Name}");

switch (xmlNode.Name)
{
Expand Down Expand Up @@ -217,12 +220,22 @@ private void InitializeProjectDictionary()

foreach (var projectNode in _model.LoadedTests.Select(tn => tn.Type == "Project"))
{
var projectInfo = new ProjectInfo(projectNode);
var name = projectNode.GetAttribute("name");

// TODO: Figure out why we are seeing duplicate assembly ids
try
{
var projectInfo = new ProjectInfo(projectNode);

foreach (var child in projectNode.Select((tn) => tn.Type == "Assembly"))
foreach (var child in projectNode.Select((tn) => tn.Type == "Assembly"))
{
projectInfo.AssembliesToRun++;
_projectLookup.Add(child.GetAttribute("id"), projectInfo);
}
}
catch(Exception ex)
{
projectInfo.AssembliesToRun++;
_projectLookup.Add(child.GetAttribute("id"), projectInfo);
log.Error("Unexpected exception", ex);
}
}
}
Expand Down
19 changes: 16 additions & 3 deletions src/TestModel/model/TestModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ public void RunTests(TestNode testNode)
if (testNode == null)
throw new ArgumentNullException(nameof(testNode));

log.Info($"Running test: {testNode.GetAttribute("name")}");
RunTests(new TestRunSpecification(testNode, CategoryFilter));
}

Expand All @@ -440,6 +441,7 @@ public void RunTests(TestSelection tests)
if (tests == null)
throw new ArgumentNullException(nameof(tests));

log.Info($"Running test: {string.Join(", ", tests.Select(node => node.GetAttribute("name").ToArray()))}");
RunTests(new TestRunSpecification(tests, CategoryFilter));
}

Expand All @@ -448,6 +450,7 @@ public void RepeatLastRun()
if (_lastTestRun == null)
throw new InvalidOperationException("RepeatLastRun called before any tests were run");

log.Info($"Running test: {string.Join(", ", _lastTestRun.SelectedTests.Select(node => node.GetAttribute("name").ToArray()))}");
RunTests(_lastTestRun);
}

Expand All @@ -466,9 +469,19 @@ public void StopTestRun(bool force)

public void SaveResults(string filePath, string format = "nunit3")
{
var resultWriter = Services.ResultService.GetResultWriter(format, new object[0]);
var results = GetResultForTest(LoadedTests.Id);
resultWriter.WriteResultFile(results.Xml, filePath);
log.Debug($"Saving test results to {filePath} in {format} format");

try
{
var resultWriter = Services.ResultService.GetResultWriter(format, new object[0]);
var results = GetResultForTest(LoadedTests.Id);
log.Debug(results.Xml.OuterXml);
resultWriter.WriteResultFile(results.Xml, filePath);
}
catch(Exception ex)
{
log.Error("Failed to save results", ex);
}
}

public TestNode GetTestById(string id)
Expand Down

0 comments on commit 44186b1

Please sign in to comment.