fix(simmy): return null from FaultGenerator when no fault is generated
FaultGenerator's implicit conversion dereferenced the nullable Outcome
returned by the underlying generator via `!.Value`, throwing
InvalidOperationException ("Nullable object must have a value.") when the
generator produced no outcome - an empty generator, or registered weights
summing to zero. ChaosFaultStrategy treats a null fault as "do not inject"
and only catches OperationCanceledException, so the exception escaped and
failed the execution the strategy was meant to leave untouched.
Propagate the nullable outcome with `?.Exception`, mirroring
OutcomeGenerator<TResult>, so no fault is injected when none is generated.
This commit is contained in:
1 parent
7121d2323f
commit
fa219d839e
2 files changed
+19
-1
No files matched your search
@@ -39,6 +39,24 @@ public class FaultGeneratorTests
|
||||
Generate(generator).ShouldBeOfType<InvalidOperationException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NoExceptionRegistered_ShouldReturnNull()
|
||||
{
|
||||
var generator = new FaultGenerator();
|
||||
|
||||
Generate(generator).ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AllWeightsZero_ShouldReturnNull()
|
||||
{
|
||||
var generator = new FaultGenerator();
|
||||
|
||||
generator.AddException<InvalidOperationException>(weight: 0);
|
||||
|
||||
Generate(generator).ShouldBeNull();
|
||||
}
|
||||
|
||||
private static Exception? Generate(FaultGenerator generator)
|
||||
{
|
||||
Func<FaultGeneratorArguments, ValueTask<Exception?>> func = generator;
|
||||
|
||||
Reference in new issue
Block a user