Reputation: 2459
we want to outsource some part of our application to an external company. These components make async requests to external websites and handle the content with html parsers or regular expressions.
async Task Do()
{
var webContent = await Get("http://...");
var match = Regex.Match(webContent);
if (IsXXX(match))
{
webContent = await Get("http://other...");
}
}
Each component is different, some make only one request, others do a lot more. We want to ensure that the CPU intensive part (Regex, Parsing) does not take a longer than 100ms and want to test it automatically as first step in the quality ensurance pipeline. Is there a way to measure the performance without the waiting time for the web requests?
I see only two solutions at the moment, but would like to know if there is better approach:
Are there some builtin solutions?
Upvotes: 3
Views: 198
Reputation: 27105
Mock the IO-bound web requests to immediately return an HTML string that will take similar CPU to process. E.g. use return Task.FromResult(XXX)
to get a task that is already completed. Then measure the method as a whole.
Note that you can use Microsoft Fakes to replace any internal call with your own method.
Upvotes: 1