Skip to content
Closed
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
47 changes: 44 additions & 3 deletions Examples/UICatalog/UICatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,40 @@ public class UICatalog
public const string LOGFILE_LOCATION = "logs";
public static UICatalogCommandLineOptions Options { get; set; }

/// <summary>
/// Sets up the ForceDriver configuration for testing purposes.
/// This is called by UICatalogMain and can also be called by tests.
/// </summary>
/// <param name="driver">The driver name to force</param>
internal static void SetupForceDriverConfig (string? driver)
{
_forceDriver = driver;

// If a driver has been specified, set it in RuntimeConfig so it persists through Init/Shutdown cycles
if (!string.IsNullOrEmpty (_forceDriver))
{
ConfigurationManager.RuntimeConfig = $$"""
{
"Application.ForceDriver": "{{_forceDriver}}"
}
""";
}
}

/// <summary>
/// Reloads RuntimeConfig to ensure ForceDriver persists before running a scenario.
/// This is called in the scenario loop and can also be called by tests.
/// </summary>
internal static void ReloadForceDriverConfig ()
{
// Ensure RuntimeConfig is applied before each scenario to preserve ForceDriver setting
if (!Options.DontEnableConfigurationManagement && !string.IsNullOrEmpty (_forceDriver))
{
ConfigurationManager.Load (ConfigLocations.Runtime);
ConfigurationManager.Apply ();
}
}

private static int Main (string [] args)
{
Console.OutputEncoding = Encoding.Default;
Expand Down Expand Up @@ -342,11 +376,11 @@ private static void ConfigFileChanged (object sender, FileSystemEventArgs e)
ConfigurationManager.Apply ();
}

private static void UICatalogMain (UICatalogCommandLineOptions options)
internal static void UICatalogMain (UICatalogCommandLineOptions options)
{
// By setting _forceDriver we ensure that if the user has specified a driver on the command line, it will be used
// regardless of what's in a config file.
Application.ForceDriver = _forceDriver = options.Driver;
SetupForceDriverConfig (options.Driver);

// If a Scenario name has been provided on the commandline
// run it and exit when done.
Expand Down Expand Up @@ -412,6 +446,9 @@ private static void UICatalogMain (UICatalogCommandLineOptions options)
Application.InitializedChanged += ApplicationOnInitializedChanged;
#endif

// Reload RuntimeConfig to ensure ForceDriver persists (part 2 of the fix)
ReloadForceDriverConfig ();

scenario.Main ();
scenario.Dispose ();

Expand Down Expand Up @@ -451,7 +488,11 @@ void ApplicationOnInitializedChanged (object? sender, EventArgs<bool> e)
scenario.StartBenchmark ();
}

Application.ForceDriver = _forceDriver!;
// For benchmarking without ConfigurationManager, set ForceDriver directly
if (!ConfigurationManager.IsEnabled && !string.IsNullOrEmpty (_forceDriver))
{
Application.ForceDriver = _forceDriver;
}

scenario.Main ();

Expand Down
3 changes: 3 additions & 0 deletions Examples/UICatalog/UICatalog.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<InformationalVersion>2.0</InformationalVersion>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<InternalsVisibleTo Include="IntegrationTests" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
Expand Down
Loading