// Copyright (c) 2025-2026 GeWuYou
// SPDX-License-Identifier: Apache-2.0
using BenchmarkDotNet.Loggers;
using System;
namespace GFramework.Cqrs.Benchmarks.Messaging;
///
/// 为 CQRS benchmark 运行打印并验证当前场景配置,避免矩阵配置与实际运行环境漂移。
///
internal static class Fixture
{
///
/// 输出当前 benchmark 配置并验证关键环境变量。
///
/// 当前 benchmark 场景名称。
/// 当前场景的处理器数量。
/// 当前场景的 pipeline 行为数量。
public static void Setup(string scenario, int handlerCount, int pipelineCount)
{
ConsoleLogger.Default.WriteLineHeader("GFramework.Cqrs benchmark config");
ConsoleLogger.Default.WriteLineInfo($"Scenario = {scenario}");
ConsoleLogger.Default.WriteLineInfo($"HandlerCount = {handlerCount}");
ConsoleLogger.Default.WriteLineInfo($"PipelineCount = {pipelineCount}");
var environmentScenario = Environment.GetEnvironmentVariable("GFRAMEWORK_CQRS_BENCHMARK_SCENARIO");
if (!string.IsNullOrWhiteSpace(environmentScenario) &&
!string.Equals(environmentScenario, scenario, StringComparison.Ordinal))
{
throw new InvalidOperationException(
$"Scenario mismatch. Expected '{environmentScenario}', actual '{scenario}'.");
}
}
}