Skip to content

Respect failure rate option with mock responses #367

Closed

Description

@xzf0587

Description

There will be not failed response if the mock file is used.

Expected behaviour

the failure mock can be triggered in mock response mode.

Actual behaviour

no failure response

Steps to reproduce

  1. launch the proxy
    ./m365proxy.exe -f 100 --mocks-file .\responses.sample.json
  2. access to some graph api by browser.

Microsoft 365 Developer Proxy Version

0.10.0

Operating system (environment)

Windows

Shell

PowerShell

Additional Info

No response

Activity

  1. changed the title [-][BUG]: failure rate option is not effective when specifying mock response[/-] [+]Respect failure rate option with mock responses[/+] on Oct 25, 2023
  2. waldekmastykarz commented on Oct 25, 2023

    @waldekmastykarz
    Collaborator

    Hey @xzf0587, this is a currently known limitation, but I fully agree that you should be able to use them in conjunction. We'll get on it.

  3. waldekmastykarz commented on Oct 25, 2023

    @waldekmastykarz
    Collaborator

    Just to clarify, if you set failure rate to 100, the mocks will never be triggered. You're basically saying that you want all requests to be failed by the (Graph)RandomErrorPlugin. If you'd like mocks to work, you'd need to lower the failure rate so that some requests are passed through, and those requests that aren't being failed would then be served from mocks. Does that make sense?

  4. xzf0587 commented on Oct 25, 2023

    @xzf0587
    Author

    Just to clarify, if you set failure rate to 100, the mocks will never be triggered. You're basically saying that you want all requests to be failed by the (Graph)RandomErrorPlugin. If you'd like mocks to work, you'd need to lower the failure rate so that some requests are passed through, and those requests that aren't being failed would then be served from mocks. Does that make sense?

    Yes. Some requests will be failed meanwhile other requests be mocked or passed through.
    And I tried the config to set failure rate to 100. But the response is not error response but mock response. Maybe you can help double confirm it.
    m365proxy.exe -f 100 --mocks-file ./responses.sample.json

  5. waldekmastykarz commented on Oct 26, 2023

    @waldekmastykarz
    Collaborator

    Ah sorry, I misunderstood. Yes, with -f 100 you should see random errors rather than mocks. Let me confirm.

  6. waldekmastykarz commented on Oct 26, 2023

    @waldekmastykarz
    Collaborator

    OK, so this works as expected with a small adjustment of the configuration.

    By default, our config is similar to:

    {
      "plugins": [
        // [...] trimmed for brevity
        {
          "name": "GraphMockResponsePlugin",
          "enabled": true,
          "pluginPath": "plugins\\m365-developer-proxy-plugins.dll",
          "configSection": "mocksPlugin"
        },
        {
          "name": "GraphRandomErrorPlugin",
          "enabled": true,
          "pluginPath": "plugins\\m365-developer-proxy-plugins.dll",
          "configSection": "graphRandomErrorsPlugin"
        }
        // [...] trimmed for brevity
      ],
      // [...] trimmed for brevity
    }

    Proxy executes plugins in the order they're defined in the config. In this case, mocks are executed before random error so if you have a mock defined for a URL, it will never reach the random error.

    If you want both random errors and mocks, you could change the order of plugins to:

    {
      "plugins": [
        // [...] trimmed for brevity
        {
          "name": "GraphRandomErrorPlugin",
          "enabled": true,
          "pluginPath": "plugins\\m365-developer-proxy-plugins.dll",
          "configSection": "graphRandomErrorsPlugin"
        },
        {
          "name": "GraphMockResponsePlugin",
          "enabled": true,
          "pluginPath": "plugins\\m365-developer-proxy-plugins.dll",
          "configSection": "mocksPlugin"
        }
        // [...] trimmed for brevity
      ],
      // [...] trimmed for brevity
    }

    That way, random errors will be handled first, and any request that's not randomly failed, will be compared against mocks.

    There's something to say for both use cases, which is why we made it configurable. I hope this helps.

    @garrytrinder we should look into clarifying this in our docs.

  7. xzf0587 commented on Oct 26, 2023

    @xzf0587
    Author

    Well. Based on this configuration, the proxy can support random errors and mock response simultaneously.
    Thanks.

  8. garrytrinder commented on Nov 3, 2023

    @garrytrinder
    Collaborator

    A new page has been add to our document this Why are random errors not thrown when using mocks

  9. locked and limited conversation to collaborators on Jun 4, 2025
  10. converted this issue into a discussion #1231 on Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions