Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework our Helix Process #76703

Merged
merged 4 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 4 additions & 32 deletions src/Tools/Source/RunTests/AssemblyScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,15 @@ internal sealed class AssemblyScheduler
/// </summary>
private static readonly int s_maxMethodCount = 500;

private readonly Options _options;

internal AssemblyScheduler(Options options)
{
_options = options;
}

public async Task<ImmutableArray<WorkItemInfo>> ScheduleAsync(ImmutableArray<AssemblyInfo> assemblies, CancellationToken cancellationToken)
public static ImmutableArray<WorkItemInfo> Schedule(
ImmutableArray<AssemblyInfo> assemblies,
ImmutableDictionary<string, TimeSpan> testHistory)
{
Logger.Log($"Scheduling {assemblies.Length} assemblies");

if (_options.Sequential || !_options.UseHelix)
{
Logger.Log("Building work items with one assembly each.");
// return individual work items per assembly that contain all the tests in that assembly.
return CreateWorkItemsForFullAssemblies(assemblies);
}

var orderedTypeInfos = assemblies.ToImmutableSortedDictionary(assembly => assembly, GetTypeInfoList);

ConsoleUtil.WriteLine($"Found {orderedTypeInfos.Values.SelectMany(t => t).SelectMany(t => t.Tests).Count()} tests to run in {orderedTypeInfos.Keys.Count()} assemblies");

// Retrieve test runtimes from azure devops historical data.
var testHistory = await TestHistoryManager.GetTestHistoryAsync(_options, cancellationToken);
if (testHistory.IsEmpty)
{
// We didn't have any test history from azure devops, just partition by test count.
Expand All @@ -101,19 +86,6 @@ public async Task<ImmutableArray<WorkItemInfo>> ScheduleAsync(ImmutableArray<Ass
addFunc: (currentTest, accumulatedExecutionTime) => currentTest.ExecutionTime + accumulatedExecutionTime);
LogWorkItems(workItems);
return workItems;

static ImmutableArray<WorkItemInfo> CreateWorkItemsForFullAssemblies(ImmutableArray<AssemblyInfo> assemblies)
{
var workItems = new List<WorkItemInfo>();
var partitionIndex = 0;
foreach (var assembly in assemblies)
{
var currentWorkItem = ImmutableSortedDictionary<AssemblyInfo, ImmutableArray<TestMethodInfo>>.Empty.Add(assembly, ImmutableArray<TestMethodInfo>.Empty);
workItems.Add(new WorkItemInfo(currentWorkItem, partitionIndex++));
}

return workItems.ToImmutableArray();
}
}

private static ImmutableSortedDictionary<AssemblyInfo, ImmutableArray<TypeInfo>> UpdateTestsWithExecutionTimes(
Expand Down Expand Up @@ -179,7 +151,7 @@ void LogResults()
}
}

private ImmutableArray<WorkItemInfo> BuildWorkItems<TWeight>(
private static ImmutableArray<WorkItemInfo> BuildWorkItems<TWeight>(
ImmutableSortedDictionary<AssemblyInfo, ImmutableArray<TypeInfo>> typeInfos,
Func<TWeight, bool> isOverLimitFunc,
Func<TestMethodInfo, TWeight, TWeight> addFunc) where TWeight : struct
Expand Down
Loading
Loading