perf(worker): launcher-configurable event queue capacity
This commit is contained in:
@@ -419,6 +419,75 @@ public sealed class MxAccessEventQueueTests
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(async () => await wait);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The queue capacity comes from the launcher-set environment variable;
|
||||
/// a missing, unparseable, below-floor, or above-ceiling value must fall
|
||||
/// back to the 10,000 default rather than throw. A bad environment value
|
||||
/// must never stop the worker's session from starting.
|
||||
/// </summary>
|
||||
/// <param name="environmentValue">Raw environment value under test.</param>
|
||||
/// <param name="expected">Expected resolved capacity.</param>
|
||||
[Theory]
|
||||
[InlineData(null, MxAccessEventQueue.DefaultCapacity)]
|
||||
[InlineData("", MxAccessEventQueue.DefaultCapacity)]
|
||||
[InlineData("not-a-number", MxAccessEventQueue.DefaultCapacity)]
|
||||
[InlineData("0", MxAccessEventQueue.DefaultCapacity)]
|
||||
[InlineData("-5", MxAccessEventQueue.DefaultCapacity)]
|
||||
[InlineData("999", MxAccessEventQueue.DefaultCapacity)]
|
||||
[InlineData("1000001", MxAccessEventQueue.DefaultCapacity)]
|
||||
[InlineData("1000", 1000)]
|
||||
[InlineData("1000000", 1000000)]
|
||||
[InlineData("50000", 50000)]
|
||||
public void ResolveCapacity_WithEnvironmentValue_FallsBackToDefaultWhenUnusable(
|
||||
string? environmentValue,
|
||||
int expected)
|
||||
{
|
||||
string? original = Environment.GetEnvironmentVariable(
|
||||
MxAccessEventQueue.CapacityEnvironmentVariableName);
|
||||
try
|
||||
{
|
||||
Environment.SetEnvironmentVariable(
|
||||
MxAccessEventQueue.CapacityEnvironmentVariableName,
|
||||
environmentValue);
|
||||
|
||||
Assert.Equal(expected, MxAccessEventQueue.ResolveCapacity());
|
||||
}
|
||||
finally
|
||||
{
|
||||
Environment.SetEnvironmentVariable(
|
||||
MxAccessEventQueue.CapacityEnvironmentVariableName,
|
||||
original);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A resolved capacity is what the queue is actually built with, so the
|
||||
/// configured headroom reaches the overflow check rather than only the
|
||||
/// resolver.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Constructor_WithResolvedCapacity_UsesEnvironmentValue()
|
||||
{
|
||||
string? original = Environment.GetEnvironmentVariable(
|
||||
MxAccessEventQueue.CapacityEnvironmentVariableName);
|
||||
try
|
||||
{
|
||||
Environment.SetEnvironmentVariable(
|
||||
MxAccessEventQueue.CapacityEnvironmentVariableName,
|
||||
"2500");
|
||||
|
||||
MxAccessEventQueue queue = new(MxAccessEventQueue.ResolveCapacity());
|
||||
|
||||
Assert.Equal(2500, queue.Capacity);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Environment.SetEnvironmentVariable(
|
||||
MxAccessEventQueue.CapacityEnvironmentVariableName,
|
||||
original);
|
||||
}
|
||||
}
|
||||
|
||||
// Mirrors MxAccessEventQueue's per-event repeated-field allowance. Kept local rather than made
|
||||
// public on the queue: the byte-budget tests state their budgets in units of that charge, so a
|
||||
// change to it should surface here as a failing bound instead of silently moving with the code.
|
||||
|
||||
Reference in New Issue
Block a user