Skip to content

Commit 6287206

Browse files
Rework our Helix Process (#76703)
* Refactor RunTests The goal of this change is to cleanly separate out the two behaviors of RunTests: locally executing tests and scheduling jobs on Helix. This is a pre-cursor to actually moving these behaviors into separate projects entirely. * Optimize WorkItem payload * more pain * Apply suggestions from code review Co-authored-by: Rikki Gibson <rikkigibson@gmail.com> --------- Co-authored-by: Rikki Gibson <rikkigibson@gmail.com>
1 parent d30e0ef commit 6287206

File tree

4 files changed

+509
-318
lines changed

4 files changed

+509
-318
lines changed

src/Tools/Source/RunTests/AssemblyScheduler.cs

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,15 @@ internal sealed class AssemblyScheduler
5151
/// </summary>
5252
private static readonly int s_maxMethodCount = 500;
5353

54-
private readonly Options _options;
55-
56-
internal AssemblyScheduler(Options options)
57-
{
58-
_options = options;
59-
}
60-
61-
public async Task<ImmutableArray<WorkItemInfo>> ScheduleAsync(ImmutableArray<AssemblyInfo> assemblies, CancellationToken cancellationToken)
54+
public static ImmutableArray<WorkItemInfo> Schedule(
55+
ImmutableArray<AssemblyInfo> assemblies,
56+
ImmutableDictionary<string, TimeSpan> testHistory)
6257
{
6358
Logger.Log($"Scheduling {assemblies.Length} assemblies");
6459

65-
if (_options.Sequential || !_options.UseHelix)
66-
{
67-
Logger.Log("Building work items with one assembly each.");
68-
// return individual work items per assembly that contain all the tests in that assembly.
69-
return CreateWorkItemsForFullAssemblies(assemblies);
70-
}
71-
7260
var orderedTypeInfos = assemblies.ToImmutableSortedDictionary(assembly => assembly, GetTypeInfoList);
73-
7461
ConsoleUtil.WriteLine($"Found {orderedTypeInfos.Values.SelectMany(t => t).SelectMany(t => t.Tests).Count()} tests to run in {orderedTypeInfos.Keys.Count()} assemblies");
7562

76-
// Retrieve test runtimes from azure devops historical data.
77-
var testHistory = await TestHistoryManager.GetTestHistoryAsync(_options, cancellationToken);
7863
if (testHistory.IsEmpty)
7964
{
8065
// We didn't have any test history from azure devops, just partition by test count.
@@ -101,19 +86,6 @@ public async Task<ImmutableArray<WorkItemInfo>> ScheduleAsync(ImmutableArray<Ass
10186
addFunc: (currentTest, accumulatedExecutionTime) => currentTest.ExecutionTime + accumulatedExecutionTime);
10287
LogWorkItems(workItems);
10388
return workItems;
104-
105-
static ImmutableArray<WorkItemInfo> CreateWorkItemsForFullAssemblies(ImmutableArray<AssemblyInfo> assemblies)
106-
{
107-
var workItems = new List<WorkItemInfo>();
108-
var partitionIndex = 0;
109-
foreach (var assembly in assemblies)
110-
{
111-
var currentWorkItem = ImmutableSortedDictionary<AssemblyInfo, ImmutableArray<TestMethodInfo>>.Empty.Add(assembly, ImmutableArray<TestMethodInfo>.Empty);
112-
workItems.Add(new WorkItemInfo(currentWorkItem, partitionIndex++));
113-
}
114-
115-
return workItems.ToImmutableArray();
116-
}
11789
}
11890

11991
private static ImmutableSortedDictionary<AssemblyInfo, ImmutableArray<TypeInfo>> UpdateTestsWithExecutionTimes(
@@ -179,7 +151,7 @@ void LogResults()
179151
}
180152
}
181153

182-
private ImmutableArray<WorkItemInfo> BuildWorkItems<TWeight>(
154+
private static ImmutableArray<WorkItemInfo> BuildWorkItems<TWeight>(
183155
ImmutableSortedDictionary<AssemblyInfo, ImmutableArray<TypeInfo>> typeInfos,
184156
Func<TWeight, bool> isOverLimitFunc,
185157
Func<TestMethodInfo, TWeight, TWeight> addFunc) where TWeight : struct

0 commit comments

Comments
 (0)