[Harness] Remove logic that builds sim tasks. (#8697)

One step closer to make the Jenkins class just know how to spin the
tasks and what tests are selected. This new class, once we can have a
clean Jenkins class will be testeable.
This commit is contained in:
Manuel de la Pena 2020-05-28 09:34:27 -04:00 коммит произвёл GitHub
Родитель 90049c3c62
Коммит 8b69ddb960
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 144 добавлений и 127 удалений

Просмотреть файл

@ -21,7 +21,7 @@ namespace Xharness.Jenkins {
public readonly ISimulatorLoader Simulators;
readonly IHardwareDeviceLoader devices;
readonly IProcessManager processManager;
readonly ITunnelBore tunnelBore;
public ITunnelBore TunnelBore { get; private set; }
readonly TestSelector testSelector;
readonly TestVariationsFactory testVariationsFactory;
readonly JenkinsDeviceLoader deviceLoader;
@ -96,7 +96,7 @@ namespace Xharness.Jenkins {
public Jenkins (Harness harness, IProcessManager processManager, IResultParser resultParser, ITunnelBore tunnelBore)
{
this.processManager = processManager ?? throw new ArgumentNullException (nameof (processManager));
this.tunnelBore = tunnelBore ?? throw new ArgumentNullException (nameof (tunnelBore));
this.TunnelBore = tunnelBore ?? throw new ArgumentNullException (nameof (tunnelBore));
Harness = harness ?? throw new ArgumentNullException (nameof (harness));
Simulators = new SimulatorLoader (processManager);
devices = new HardwareDeviceLoader (processManager);
@ -108,53 +108,6 @@ namespace Xharness.Jenkins {
markdownReportWriter = new MarkdownReportWriter ();
}
IEnumerable<RunSimulatorTask> CreateRunSimulatorTaskAsync (MSBuildTask buildTask)
{
var runtasks = new List<RunSimulatorTask> ();
TestTarget [] targets = buildTask.Platform.GetAppRunnerTargets ();
TestPlatform [] platforms;
bool [] ignored;
switch (buildTask.Platform) {
case TestPlatform.tvOS:
platforms = new TestPlatform [] { TestPlatform.tvOS };
ignored = new [] { false };
break;
case TestPlatform.watchOS:
platforms = new TestPlatform [] { TestPlatform.watchOS_32 };
ignored = new [] { false };
break;
case TestPlatform.iOS_Unified:
platforms = new TestPlatform [] { TestPlatform.iOS_Unified32, TestPlatform.iOS_Unified64 };
ignored = new [] { !IncludeiOS32, false};
break;
case TestPlatform.iOS_TodayExtension64:
targets = new TestTarget[] { TestTarget.Simulator_iOS64 };
platforms = new TestPlatform[] { TestPlatform.iOS_TodayExtension64 };
ignored = new [] { false };
break;
default:
throw new NotImplementedException ();
}
for (int i = 0; i < targets.Length; i++) {
var sims = Simulators.SelectDevices (targets [i], SimulatorLoadLog, false);
runtasks.Add (new RunSimulatorTask (
jenkins: this,
simulators: Simulators,
buildTask: buildTask,
processManager: processManager,
tunnelBore: tunnelBore,
candidates: sims) {
Platform = platforms [i],
Ignored = ignored[i] || buildTask.Ignored
});
}
return runtasks;
}
public bool IsIncluded (TestProject project)
{
if (!project.IsExecutableProject)
@ -180,76 +133,6 @@ namespace Xharness.Jenkins {
return true;
}
async Task<IEnumerable<AppleTestTask>> CreateRunSimulatorTasksAsync ()
{
var runSimulatorTasks = new List<RunSimulatorTask> ();
foreach (var project in Harness.IOSTestProjects) {
if (!project.IsExecutableProject)
continue;
bool ignored = !IncludeSimulator;
if (!IsIncluded (project))
ignored = true;
var ps = new List<Tuple<TestProject, TestPlatform, bool>> ();
if (!project.SkipiOSVariation)
ps.Add (new Tuple<TestProject, TestPlatform, bool> (project, TestPlatform.iOS_Unified, ignored || !IncludeiOS64));
if (project.MonoNativeInfo != null)
ps.Add (new Tuple<TestProject, TestPlatform, bool> (project, TestPlatform.iOS_TodayExtension64, ignored || !IncludeiOS64));
if (!project.SkiptvOSVariation)
ps.Add (new Tuple<TestProject, TestPlatform, bool> (project.AsTvOSProject (), TestPlatform.tvOS, ignored || !IncludetvOS));
if (!project.SkipwatchOSVariation)
ps.Add (new Tuple<TestProject, TestPlatform, bool> (project.AsWatchOSProject (), TestPlatform.watchOS, ignored || !IncludewatchOS));
var configurations = project.Configurations;
if (configurations == null)
configurations = new string [] { "Debug" };
foreach (var config in configurations) {
foreach (var pair in ps) {
var derived = new MSBuildTask (jenkins: this, testProject: project, processManager: processManager) {
ProjectConfiguration = config,
ProjectPlatform = "iPhoneSimulator",
Platform = pair.Item2,
Ignored = pair.Item3,
TestName = project.Name,
Dependency = project.Dependency,
};
derived.CloneTestProject (MainLog, processManager, pair.Item1);
var simTasks = CreateRunSimulatorTaskAsync (derived);
runSimulatorTasks.AddRange (simTasks);
foreach (var task in simTasks) {
if (configurations.Length > 1)
task.Variation = config;
task.TimeoutMultiplier = project.TimeoutMultiplier;
}
}
}
}
var testVariations = testVariationsFactory.CreateTestVariations (runSimulatorTasks, (buildTask, test, candidates) =>
new RunSimulatorTask (
jenkins: this,
simulators: Simulators,
buildTask: buildTask,
processManager: processManager,
tunnelBore: tunnelBore,
candidates: candidates?.Cast<SimulatorDevice> () ?? test.Candidates)).ToList ();
foreach (var tv in testVariations) {
if (!tv.Ignored)
await tv.FindSimulatorAsync ();
}
var rv = new List<AggregatedRunSimulatorTask> ();
foreach (var taskGroup in testVariations.GroupBy ((RunSimulatorTask task) => task.Device?.UDID ?? task.Candidates.ToString ())) {
rv.Add (new AggregatedRunSimulatorTask (jenkins: this, tasks: taskGroup) {
TestName = $"Tests for {taskGroup.Key}",
});
}
return rv;
}
Task<IEnumerable<AppleTestTask>> CreateRunDeviceTasksAsync ()
{
var rv = new List<RunDeviceTask> ();
@ -277,7 +160,7 @@ namespace Xharness.Jenkins {
devices: devices,
buildTask: build64,
processManager: processManager,
tunnelBore: tunnelBore,
tunnelBore: TunnelBore,
errorKnowledgeBase: ErrorKnowledgeBase,
useTcpTunnel: Harness.UseTcpTunnel,
candidates: devices.Connected64BitIOS.Where (d => project.IsSupported (d.DevicePlatform, d.ProductVersion))) { Ignored = !IncludeiOS64 });
@ -294,7 +177,7 @@ namespace Xharness.Jenkins {
devices: devices,
buildTask: build32,
processManager: processManager,
tunnelBore: tunnelBore,
tunnelBore: TunnelBore,
errorKnowledgeBase: ErrorKnowledgeBase,
useTcpTunnel: Harness.UseTcpTunnel,
candidates: devices.Connected32BitIOS.Where (d => project.IsSupported (d.DevicePlatform, d.ProductVersion))) { Ignored = !IncludeiOS32 });
@ -312,7 +195,7 @@ namespace Xharness.Jenkins {
devices: devices,
buildTask: buildToday,
processManager: processManager,
tunnelBore: tunnelBore,
tunnelBore: TunnelBore,
errorKnowledgeBase: ErrorKnowledgeBase,
useTcpTunnel: Harness.UseTcpTunnel,
candidates: devices.Connected64BitIOS.Where (d => project.IsSupported (d.DevicePlatform, d.ProductVersion))) { Ignored = !IncludeiOSExtensions, BuildOnly = ForceExtensionBuildOnly });
@ -332,7 +215,7 @@ namespace Xharness.Jenkins {
devices: devices,
buildTask: buildTV,
processManager: processManager,
tunnelBore: tunnelBore,
tunnelBore: TunnelBore,
errorKnowledgeBase: ErrorKnowledgeBase,
useTcpTunnel: Harness.UseTcpTunnel,
candidates: devices.ConnectedTV.Where (d => project.IsSupported (d.DevicePlatform, d.ProductVersion))) { Ignored = !IncludetvOS });
@ -353,7 +236,7 @@ namespace Xharness.Jenkins {
devices: devices,
buildTask: buildWatch32,
processManager: processManager,
tunnelBore: tunnelBore,
tunnelBore: TunnelBore,
errorKnowledgeBase: ErrorKnowledgeBase,
useTcpTunnel: Harness.UseTcpTunnel,
candidates: devices.ConnectedWatch) { Ignored = !IncludewatchOS });
@ -372,7 +255,7 @@ namespace Xharness.Jenkins {
devices: devices,
buildTask: buildWatch64_32,
processManager: processManager,
tunnelBore: tunnelBore,
tunnelBore: TunnelBore,
errorKnowledgeBase: ErrorKnowledgeBase,
useTcpTunnel: Harness.UseTcpTunnel,
candidates: devices.ConnectedWatch32_64.Where (d => project.IsSupported (d.DevicePlatform, d.ProductVersion))) { Ignored = !IncludewatchOS });
@ -392,7 +275,7 @@ namespace Xharness.Jenkins {
devices: devices,
buildTask: buildTask,
processManager: processManager,
tunnelBore: tunnelBore,
tunnelBore: TunnelBore,
errorKnowledgeBase: ErrorKnowledgeBase,
useTcpTunnel: Harness.UseTcpTunnel,
candidates: candidates?.Cast<IHardwareDevice> () ?? test.Candidates)));
@ -409,7 +292,8 @@ namespace Xharness.Jenkins {
deviceLoader.LoadAllAsync ().DoNotAwait ();
var loadsim = CreateRunSimulatorTasksAsync ()
var simTasksFactory = new RunSimulatorTasksFactory ();
var loadsim = simTasksFactory.CreateAsync (this, processManager, testVariationsFactory)
.ContinueWith ((v) => { Console.WriteLine ("Simulator tasks created"); Tasks.AddRange (v.Result); });
//Tasks.AddRange (await CreateRunSimulatorTasksAsync ());

Просмотреть файл

@ -0,0 +1,132 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.DotNet.XHarness.iOS.Shared;
using Microsoft.DotNet.XHarness.iOS.Shared.Execution;
using Microsoft.DotNet.XHarness.iOS.Shared.Hardware;
using Microsoft.DotNet.XHarness.iOS.Shared.Tasks;
using Xharness.Jenkins.TestTasks;
namespace Xharness.Jenkins {
// lets try and keep this class stateless, will make our lifes better
class RunSimulatorTasksFactory {
public async Task<IEnumerable<ITestTask>> CreateAsync (Jenkins jenkins, IProcessManager processManager, TestVariationsFactory testVariationsFactory)
{
var runSimulatorTasks = new List<RunSimulatorTask> ();
foreach (var project in jenkins.Harness.IOSTestProjects) {
if (!project.IsExecutableProject)
continue;
bool ignored = !jenkins.IncludeSimulator;
if (!jenkins.IsIncluded (project))
ignored = true;
var ps = new List<Tuple<TestProject, TestPlatform, bool>> ();
if (!project.SkipiOSVariation)
ps.Add (new Tuple<TestProject, TestPlatform, bool> (project, TestPlatform.iOS_Unified, ignored || !jenkins.IncludeiOS64));
if (project.MonoNativeInfo != null)
ps.Add (new Tuple<TestProject, TestPlatform, bool> (project, TestPlatform.iOS_TodayExtension64, ignored || !jenkins.IncludeiOS64));
if (!project.SkiptvOSVariation)
ps.Add (new Tuple<TestProject, TestPlatform, bool> (project.AsTvOSProject (), TestPlatform.tvOS, ignored || !jenkins.IncludetvOS));
if (!project.SkipwatchOSVariation)
ps.Add (new Tuple<TestProject, TestPlatform, bool> (project.AsWatchOSProject (), TestPlatform.watchOS, ignored || !jenkins.IncludewatchOS));
var configurations = project.Configurations;
if (configurations == null)
configurations = new string [] { "Debug" };
foreach (var config in configurations) {
foreach (var pair in ps) {
var derived = new MSBuildTask (jenkins: jenkins, testProject: project, processManager: processManager) {
ProjectConfiguration = config,
ProjectPlatform = "iPhoneSimulator",
Platform = pair.Item2,
Ignored = pair.Item3,
TestName = project.Name,
Dependency = project.Dependency,
};
derived.CloneTestProject (jenkins.MainLog, processManager, pair.Item1);
var simTasks = CreateAsync (jenkins, processManager, derived);
runSimulatorTasks.AddRange (simTasks);
foreach (var task in simTasks) {
if (configurations.Length > 1)
task.Variation = config;
task.TimeoutMultiplier = project.TimeoutMultiplier;
}
}
}
}
var testVariations = testVariationsFactory.CreateTestVariations (runSimulatorTasks, (buildTask, test, candidates) =>
new RunSimulatorTask (
jenkins: jenkins,
simulators: jenkins.Simulators,
buildTask: buildTask,
processManager: processManager,
tunnelBore: jenkins.TunnelBore,
candidates: candidates?.Cast<SimulatorDevice> () ?? test.Candidates)).ToList ();
foreach (var tv in testVariations) {
if (!tv.Ignored)
await tv.FindSimulatorAsync ();
}
var rv = new List<AggregatedRunSimulatorTask> ();
foreach (var taskGroup in testVariations.GroupBy ((RunSimulatorTask task) => task.Device?.UDID ?? task.Candidates.ToString ())) {
rv.Add (new AggregatedRunSimulatorTask (jenkins: jenkins, tasks: taskGroup) {
TestName = $"Tests for {taskGroup.Key}",
});
}
return rv;
}
IEnumerable<RunSimulatorTask> CreateAsync (Jenkins jenkins, IProcessManager processManager, MSBuildTask buildTask)
{
var runtasks = new List<RunSimulatorTask> ();
TestTarget [] targets = buildTask.Platform.GetAppRunnerTargets ();
TestPlatform [] platforms;
bool [] ignored;
switch (buildTask.Platform) {
case TestPlatform.tvOS:
platforms = new TestPlatform [] { TestPlatform.tvOS };
ignored = new [] { false };
break;
case TestPlatform.watchOS:
platforms = new TestPlatform [] { TestPlatform.watchOS_32 };
ignored = new [] { false };
break;
case TestPlatform.iOS_Unified:
platforms = new TestPlatform [] { TestPlatform.iOS_Unified32, TestPlatform.iOS_Unified64 };
ignored = new [] { !jenkins.IncludeiOS32, false };
break;
case TestPlatform.iOS_TodayExtension64:
targets = new TestTarget [] { TestTarget.Simulator_iOS64 };
platforms = new TestPlatform [] { TestPlatform.iOS_TodayExtension64 };
ignored = new [] { false };
break;
default:
throw new NotImplementedException ();
}
for (int i = 0; i < targets.Length; i++) {
var sims = jenkins.Simulators.SelectDevices (targets [i], jenkins.SimulatorLoadLog, false);
runtasks.Add (new RunSimulatorTask (
jenkins: jenkins,
simulators: jenkins.Simulators,
buildTask: buildTask,
processManager: processManager,
tunnelBore: jenkins.TunnelBore,
candidates: sims) {
Platform = platforms [i],
Ignored = ignored [i] || buildTask.Ignored
});
}
return runtasks;
}
}
}

Просмотреть файл

@ -140,6 +140,7 @@
<Compile Include="Jenkins\Reports\IReportWriter.cs" />
<Compile Include="Jenkins\Reports\MarkdownReportWriter.cs" />
<Compile Include="Jenkins\Reports\HtmlReportWriter.cs" />
<Compile Include="Jenkins\RunSimulatorTasksFactory.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\tools\common\SdkVersions.cs">