Skip to content

Make LatencyPlugin's maxMs inclusive - #1930

Open
waldekmastykarz with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-latencyplugin-maxms-issue
Open

waldekmastykarz with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-latencyplugin-maxms-issue

Conversation

Copilot AI commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

LatencyPlugin picked its delay with Random.Next(MinMs, MaxMs). That method excludes the upper bound, so the configured maxMs was never applied. The schema describes maxMs as the maximum delay, so it should be a possible value.

Changes

  • LatencyPlugin: both ApplyDelayAsync overloads (HTTP and stdio) now call a new internal helper, GetDelay, which picks from minMs to maxMs inclusive. The upper bound is computed as a long, so MaxMs + 1 can't overflow when maxMs is int.MaxValue.

    internal static int GetDelay(Random random, int minMs, int maxMs) =>
        (int)random.NextInt64(minMs, (long)maxMs + 1);
  • Tests (BehaviorPluginsIntegrationTests): the new test checks three cases:

    • With 0..1, the delay is sometimes 1. The old code always returned 0.
    • With min == max, the delay equals that value.
    • maxMs = int.MaxValue doesn't overflow.

    GetDelay is reachable from the tests through the existing InternalsVisibleTo entry.

minMs > maxMs still throws, as it did before.

Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com>
Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix LatencyPlugin to apply inclusive maxMs Make LatencyPlugin's maxMs inclusive 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

The focused fix handles inclusive bounds safely with regression coverage; tests were not executed.

No open issues 🎉

What changed in this PR

Fixes #1927 by allowing LatencyPlugin to select the configured maxMs delay.

Changes:

  • Uses a shared, overflow-safe inclusive delay calculation for HTTP and stdio.
  • Adds regression coverage for inclusive, equal, and int.MaxValue bounds.
File Description
DevProxy.Plugins/​Behavior/​LatencyPlugin.cs Applies inclusive bounds to both delay paths.
DevProxy.Integration.Tests/​BehaviorPluginsIntegrationTests.cs Tests upper-bound inclusion and boundary cases.

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

This branch has not been deployed

No deployments
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.

LatencyPlugin never applies maxMs because the upper bound is exclusive

3 participants