dev-proxy: Add support for slow responses

Extend the proxy with ability to test slow API responses.

Rationale

One aspect of testing how applications use an API is how they respond to slow API responses. Is it obvious that content is loading? Is the whole application unresponsive? Is the application failing because it expects a response in a certain timeframe? Graph Developer Proxy can help developers validate the user experience when the API responds slowly.

Spec

  • introduce app setting named minDelayMs, that defines the lower range of the delay in milliseconds added to API response. Default value 500
  • introduce app setting named maxDelayMs, that defines the upper range of the delay in milliseconds added to API response. Default value 10000
  • introduce option named --min-delay that allows users to override the value of minDelayMs as configured in appSettings. When not specified, uses the value from appSettings.
  • introduce option named --max-delay that allows users to override the value of maxDelayMs as configured in appSettings. When not specified, uses the value from appSettings.
  • introduce option named --slow-responses which is a flag. When used, it will cause the proxy to add a random delay from range minDelayMs <= x <= maxDelayMs to each API response (mocked or not)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Just want to add that we should think about the supporting documentation for this in the spec so we don’t forget about how to articulate this new feature to our audience. At minimum I think we should provide a How-to guide and update the technical reference.

This isn’t really about the network speed, which developers can simulate using browser tooling. This is more about the delayed response from the server, which would occur when the server is under load and it takes a while to process and respond to a request, before it’s sent over the network.

Updated spec. Have I captured everything correctly @gavinbarron?

That captures everything correctly from my point of view.

Is there a reason where we specify the minDelayMs?

I assume you’re meaning the Ms suffix on these settings? IMO when reading the code inside the proxy that uses this setting it would also have the Ms suffix and make it more apparent what units the delay is in without the need to change to using jsonc and it’s would also be visible in the C# code in this form. I’m all for eliminating things that don’t have value, but keeping the affordance of settings high through convention based naming is a nice thing to me, I hate to have to go look for documentation to for the units of time being used in these scenarios.

--min-delay and --max-delay seem like good candidates with --slow-responses using the min and max delay defaults that are in the appsettings.json file? providing either --min-delay or --max-delay will enable slow response mode and use the default for the unspecified value

Great idea @waldekmastykarz I like this idea a lot, when working with asynchronous code we cannot assume that calls are always timely, or consistent.

Maybe we could provide some preset values here, similar in the way that Dev Tools does to mimic different network conditions, where they provide Slow 3G or Fast 4G profiles (https://developer.chrome.com/docs/devtools/network/reference/#throttling).

I could see this help with scenarios where apps are used on mobile devices away from the office and developers want to recreate those conditions.