Skip to content

Fix off-by-one in random error plugins' failure rate check - #1929

Merged
waldekmastykarz merged 5 commits into
mainfrom
copilot/fix-random-error-plugin-rates
Oct 21, 2026
Merged

waldekmastykarz merged 5 commits into
mainfrom
copilot/fix-random-error-plugin-rates

Conversation

Copilot AI commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

GenericRandomErrorPlugin and GraphRandomErrorPlugin don't apply the configured rate exactly. Random.Next(1, 100) excludes 100, so it only returns 1–99. As a result, rate: 99 fails every request, and every other rate fails slightly more often than configured (rate: 50 fails about 50.5% of requests).

Changes

  • Rate check (GenericRandomErrorPlugin.ShouldFail, GraphRandomErrorPlugin.ShouldFail): changed the roll to 0–99 and the comparison to strict, so rate: N fails N% of requests on average.

    - _random.Next(1, 100) <= Configuration.Rate
    + _random.Next(0, 100) <  Configuration.Rate

    rate: 0 never fails and rate: 100 always fails, same as before.

  • Test (BehaviorPluginsIntegrationTests.GenericRandomError_Rate99_SometimesPassesThrough): sends requests through the proxy with rate: 99 until one reaches the origin, up to 2,000 attempts. It fails on the old code. The test is random, so it can fail even with the fix, but only with a probability of about 2×10⁻⁹. There is no matching test for GraphRandomErrorPlugin.

Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com>
@waldekmastykarz
waldekmastykarz requested a balanced review from Copilot October 20, 2026 08:19
Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix random error plugins to correctly apply configured rate Fix off-by-one in random error plugins' failure rate check Oct 20, 2026
Copilot AI requested a review from waldekmastykarz October 20, 2026 08:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

Static review identified no blocking issues; the corrections match the reported defect, though tests were not executed.

No open issues 🎉

What changed in this PR

Corrects random-error probabilities in both plugins, addressing #1926 so configured rates apply accurately on average.

Changes:

  • Fixes the random sampling range and comparison.
  • Adds a regression test confirming rate: 99 permits requests through.
  • Updates transitive dependency lock entries.
File Description
DevProxy/​packages.lock.json Updates application dependency lock entries.
DevProxy.Proxy.Kestrel/​packages.lock.json Updates proxy-engine dependency lock entries.
DevProxy.Plugins/​Behavior/​GraphRandomErrorPlugin.cs Corrects Graph error probability.
DevProxy.Plugins/​Behavior/​GenericRandomErrorPlugin.cs Corrects generic error probability.
DevProxy.Integration.Tests/​BehaviorPluginsIntegrationTests.cs Adds rate-99 regression coverage.

Review effort: Balanced

@waldekmastykarz
waldekmastykarz marked this pull request as ready for review October 20, 2026 17:49
@waldekmastykarz
waldekmastykarz requested a review from a team as a code owner October 20, 2026 17:49
@waldekmastykarz

Copy link
Copy Markdown
Collaborator

@copilot build is failing. Fix

Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com>

Copilot AI commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

@copilot build is failing. Fix

Fixed in 037e040. The DevProxy and Kestrel NuGet lock files now match the updated project dependency graph; locked restore, solution build, and the focused integration test pass.

@waldekmastykarz
waldekmastykarz merged commit 6b2ba70 into main Oct 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Random error plugins: rate 99 behaves like 100 and all rates are slightly off

3 participants