Restructure solution layout by module
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using StellaOps.Bench.Notify.Baseline;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.Bench.Notify.Tests;
|
||||
|
||||
public sealed class BaselineLoaderTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task LoadAsync_ReadsBaselineEntries()
|
||||
{
|
||||
var path = Path.GetTempFileName();
|
||||
try
|
||||
{
|
||||
await File.WriteAllTextAsync(
|
||||
path,
|
||||
"scenario,iterations,events,deliveries,mean_ms,p95_ms,max_ms,mean_throughput_per_sec,min_throughput_per_sec,max_allocated_mb\n" +
|
||||
"notify_dispatch_density_05,5,5000,25000,120.5,150.1,199.9,42000.5,39000.2,85.7\n");
|
||||
|
||||
var entries = await BaselineLoader.LoadAsync(path, CancellationToken.None);
|
||||
var entry = Assert.Single(entries);
|
||||
|
||||
Assert.Equal("notify_dispatch_density_05", entry.Key);
|
||||
Assert.Equal(5, entry.Value.Iterations);
|
||||
Assert.Equal(5000, entry.Value.EventCount);
|
||||
Assert.Equal(25000, entry.Value.DeliveryCount);
|
||||
Assert.Equal(120.5, entry.Value.MeanMs);
|
||||
Assert.Equal(39000.2, entry.Value.MinThroughputPerSecond);
|
||||
Assert.Equal(85.7, entry.Value.MaxAllocatedMb);
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using System.Linq;
|
||||
using StellaOps.Bench.Notify.Baseline;
|
||||
using StellaOps.Bench.Notify.Reporting;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.Bench.Notify.Tests;
|
||||
|
||||
public sealed class BenchmarkScenarioReportTests
|
||||
{
|
||||
[Fact]
|
||||
public void RegressionDetection_FlagsLatencies()
|
||||
{
|
||||
var result = new ScenarioResult(
|
||||
Id: "scenario",
|
||||
Label: "Scenario",
|
||||
Iterations: 3,
|
||||
TotalEvents: 1000,
|
||||
TotalRules: 100,
|
||||
ActionsPerRule: 2,
|
||||
AverageMatchesPerEvent: 10,
|
||||
MinMatchesPerEvent: 8,
|
||||
MaxMatchesPerEvent: 12,
|
||||
AverageDeliveriesPerEvent: 20,
|
||||
TotalDeliveries: 20000,
|
||||
MeanMs: 200,
|
||||
P95Ms: 250,
|
||||
MaxMs: 300,
|
||||
MeanThroughputPerSecond: 50000,
|
||||
MinThroughputPerSecond: 40000,
|
||||
MaxAllocatedMb: 100,
|
||||
ThresholdMs: null,
|
||||
MinThroughputThresholdPerSecond: null,
|
||||
MaxAllocatedThresholdMb: null);
|
||||
|
||||
var baseline = new BaselineEntry(
|
||||
ScenarioId: "scenario",
|
||||
Iterations: 3,
|
||||
EventCount: 1000,
|
||||
DeliveryCount: 20000,
|
||||
MeanMs: 150,
|
||||
P95Ms: 180,
|
||||
MaxMs: 200,
|
||||
MeanThroughputPerSecond: 60000,
|
||||
MinThroughputPerSecond: 50000,
|
||||
MaxAllocatedMb: 90);
|
||||
|
||||
var report = new BenchmarkScenarioReport(result, baseline, regressionLimit: 1.1);
|
||||
|
||||
Assert.True(report.DurationRegressionBreached);
|
||||
Assert.True(report.ThroughputRegressionBreached);
|
||||
Assert.Contains(report.BuildRegressionFailureMessages(), message => message.Contains("max duration"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegressionDetection_NoBaseline_NoBreaches()
|
||||
{
|
||||
var result = new ScenarioResult(
|
||||
Id: "scenario",
|
||||
Label: "Scenario",
|
||||
Iterations: 3,
|
||||
TotalEvents: 1000,
|
||||
TotalRules: 100,
|
||||
ActionsPerRule: 2,
|
||||
AverageMatchesPerEvent: 10,
|
||||
MinMatchesPerEvent: 8,
|
||||
MaxMatchesPerEvent: 12,
|
||||
AverageDeliveriesPerEvent: 20,
|
||||
TotalDeliveries: 20000,
|
||||
MeanMs: 200,
|
||||
P95Ms: 250,
|
||||
MaxMs: 300,
|
||||
MeanThroughputPerSecond: 50000,
|
||||
MinThroughputPerSecond: 40000,
|
||||
MaxAllocatedMb: 100,
|
||||
ThresholdMs: null,
|
||||
MinThroughputThresholdPerSecond: null,
|
||||
MaxAllocatedThresholdMb: null);
|
||||
|
||||
var report = new BenchmarkScenarioReport(result, baseline: null, regressionLimit: null);
|
||||
|
||||
Assert.False(report.DurationRegressionBreached);
|
||||
Assert.False(report.ThroughputRegressionBreached);
|
||||
Assert.Empty(report.BuildRegressionFailureMessages());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Threading;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.Bench.Notify.Tests;
|
||||
|
||||
public sealed class NotifyScenarioRunnerTests
|
||||
{
|
||||
[Fact]
|
||||
public void Execute_ComputesDeterministicMetrics()
|
||||
{
|
||||
var config = new NotifyScenarioConfig
|
||||
{
|
||||
Id = "unit_test",
|
||||
EventCount = 500,
|
||||
RuleCount = 40,
|
||||
ActionsPerRule = 3,
|
||||
MatchRate = 0.25,
|
||||
TenantCount = 4,
|
||||
ChannelCount = 16
|
||||
};
|
||||
|
||||
var runner = new NotifyScenarioRunner(config);
|
||||
var result = runner.Execute(2, CancellationToken.None);
|
||||
|
||||
Assert.Equal(config.ResolveEventCount(), result.TotalEvents);
|
||||
Assert.Equal(config.ResolveRuleCount(), result.TotalRules);
|
||||
Assert.Equal(config.ResolveActionsPerRule(), result.ActionsPerRule);
|
||||
Assert.True(result.TotalMatches > 0);
|
||||
Assert.Equal(result.TotalMatches * result.ActionsPerRule, result.TotalDeliveries);
|
||||
Assert.Equal(2, result.Durations.Count);
|
||||
Assert.All(result.Durations, value => Assert.True(value > 0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using System.IO;
|
||||
using StellaOps.Bench.Notify.Baseline;
|
||||
using StellaOps.Bench.Notify.Reporting;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.Bench.Notify.Tests;
|
||||
|
||||
public sealed class PrometheusWriterTests
|
||||
{
|
||||
[Fact]
|
||||
public void Write_EmitsScenarioMetrics()
|
||||
{
|
||||
var result = new ScenarioResult(
|
||||
Id: "scenario",
|
||||
Label: "Scenario",
|
||||
Iterations: 3,
|
||||
TotalEvents: 1000,
|
||||
TotalRules: 100,
|
||||
ActionsPerRule: 2,
|
||||
AverageMatchesPerEvent: 10,
|
||||
MinMatchesPerEvent: 8,
|
||||
MaxMatchesPerEvent: 12,
|
||||
AverageDeliveriesPerEvent: 20,
|
||||
TotalDeliveries: 20000,
|
||||
MeanMs: 200,
|
||||
P95Ms: 250,
|
||||
MaxMs: 300,
|
||||
MeanThroughputPerSecond: 50000,
|
||||
MinThroughputPerSecond: 40000,
|
||||
MaxAllocatedMb: 100,
|
||||
ThresholdMs: 900,
|
||||
MinThroughputThresholdPerSecond: 35000,
|
||||
MaxAllocatedThresholdMb: 150);
|
||||
|
||||
var baseline = new BaselineEntry(
|
||||
ScenarioId: "scenario",
|
||||
Iterations: 3,
|
||||
EventCount: 1000,
|
||||
DeliveryCount: 20000,
|
||||
MeanMs: 180,
|
||||
P95Ms: 210,
|
||||
MaxMs: 240,
|
||||
MeanThroughputPerSecond: 52000,
|
||||
MinThroughputPerSecond: 41000,
|
||||
MaxAllocatedMb: 95);
|
||||
|
||||
var report = new BenchmarkScenarioReport(result, baseline);
|
||||
|
||||
var path = Path.GetTempFileName();
|
||||
try
|
||||
{
|
||||
PrometheusWriter.Write(path, new[] { report });
|
||||
var content = File.ReadAllText(path);
|
||||
|
||||
Assert.Contains("notify_dispatch_bench_mean_ms", content);
|
||||
Assert.Contains("scenario\"} 200", content);
|
||||
Assert.Contains("notify_dispatch_bench_baseline_mean_ms", content);
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<LangVersion>preview</LangVersion>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<UseConcelierTestInfra>false</UseConcelierTestInfra>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\StellaOps.Bench.Notify\StellaOps.Bench.Notify.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user