Skip to content
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
2 changes: 1 addition & 1 deletion TUnit.Engine.Tests/GlobalHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class GlobalHooks
public static async Task BuildTestProject()
{
var result = await CliWrap.Cli.Wrap("dotnet")
.WithArguments(["build", "-c", GetConfiguration(), "--no-restore"])
.WithArguments(["build", "-c", GetConfiguration()])
.WithWorkingDirectory(FileSystemHelpers.FindFile(x => x.Name == "TUnit.TestProject.csproj")!.DirectoryName!)
.WithValidation(CliWrap.CommandResultValidation.None)
.ExecuteBufferedAsync();
Expand Down
56 changes: 52 additions & 4 deletions TUnit.Engine/Framework/TUnitServiceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using TUnit.Engine.Helpers;
using TUnit.Engine.Interfaces;
using TUnit.Engine.Logging;
using TUnit.Engine.Scheduling;
using TUnit.Engine.Services;

namespace TUnit.Engine.Framework;
Expand Down Expand Up @@ -44,6 +45,7 @@ public ITestExecutionFilter? Filter
public ITestFinder TestFinder { get; }
public TUnitInitializer Initializer { get; }
public CancellationTokenSource FailFastCancellationSource { get; }
public ParallelLimitLockProvider ParallelLimitLockProvider { get; }

public TUnitServiceProvider(IExtension extension,
ExecuteRequestContext context,
Expand All @@ -59,7 +61,7 @@ public TUnitServiceProvider(IExtension extension,
var outputDevice = frameworkServiceProvider.GetOutputDevice();
CommandLineOptions = frameworkServiceProvider.GetCommandLineOptions();
var configuration = frameworkServiceProvider.GetConfiguration();

TestContext.Configuration = new ConfigurationAdapter(configuration);

VerbosityService = Register(new VerbosityService(CommandLineOptions));
Expand All @@ -86,6 +88,8 @@ public TUnitServiceProvider(IExtension extension,

HookCollectionService = Register<IHookCollectionService>(new HookCollectionService());

ParallelLimitLockProvider = Register(new ParallelLimitLockProvider());

ContextProvider = Register(new ContextProvider(this, TestSessionId, Filter?.ToString()));

HookOrchestrator = Register(new HookOrchestrator(HookCollectionService, Logger, ContextProvider, this));
Expand Down Expand Up @@ -129,7 +133,7 @@ public TUnitServiceProvider(IExtension extension,

// Create single test executor with ExecutionContext support
var singleTestExecutor = Register<ISingleTestExecutor>(
new SingleTestExecutor(Logger, EventReceiverOrchestrator, HookCollectionService, context.Request.Session.SessionUid));
new SingleTestExecutor(Logger, EventReceiverOrchestrator, HookCollectionService, CancellationToken, context.Request.Session.SessionUid));

// Create the HookOrchestratingTestExecutorAdapter
// Note: We'll need to update this to handle dynamic dependencies properly
Expand All @@ -146,14 +150,24 @@ public TUnitServiceProvider(IExtension extension,
isFailFastEnabled,
FailFastCancellationSource,
Logger,
HookOrchestrator));
HookOrchestrator,
ParallelLimitLockProvider));

// Create scheduler configuration from command line options
var schedulerConfig = GetSchedulerConfiguration();
var testGroupingService = Register<ITestGroupingService>(new TestGroupingService());
var testScheduler = Register<ITestScheduler>(new Scheduling.TestScheduler(
Logger,
testGroupingService,
MessageBus,
schedulerConfig));

TestExecutor = Register(new TestExecutor(
singleTestExecutor,
CommandLineOptions,
Logger,
loggerFactory,
testScheduler: null,
testScheduler,
serviceProvider: this,
hookOrchestratingTestExecutorAdapter,
ContextProvider,
Expand Down Expand Up @@ -230,6 +244,40 @@ private static bool GetUseSourceGeneration(ICommandLineOptions commandLineOption
return SourceRegistrar.IsEnabled;
}

private SchedulerConfiguration GetSchedulerConfiguration()
{
var config = new SchedulerConfiguration();

// Handle --maximum-parallel-tests
if (CommandLineOptions.TryGetOptionArgumentList(
MaximumParallelTestsCommandProvider.MaximumParallelTests,
out var args) && args.Length > 0)
{
if (int.TryParse(args[0], out var maxParallelTests) && maxParallelTests > 0)
{
config.MaxParallelism = maxParallelTests;
config.AdaptiveMaxParallelism = maxParallelTests;
}
}

// Handle --parallelism-strategy
if (CommandLineOptions.TryGetOptionArgumentList(
ParallelismStrategyCommandProvider.ParallelismStrategy,
out var strategyArgs) && strategyArgs.Length > 0)
{
var strategy = strategyArgs[0].ToLowerInvariant();
config.Strategy = strategy == "fixed" ? ParallelismStrategy.Fixed : ParallelismStrategy.Adaptive;
}

// Handle --adaptive-metrics
if (CommandLineOptions.IsOptionSet(AdaptiveMetricsCommandProvider.AdaptiveMetrics))
{
config.EnableAdaptiveMetrics = true;
}

return config;
}

public async ValueTask DisposeAsync()
{
foreach (var service in _services.Values)
Expand Down
243 changes: 0 additions & 243 deletions TUnit.Engine/Scheduling/AdaptiveParallelismController.cs

This file was deleted.

Loading
Loading