Ok, I'm stuck. I've got a Web API that I benchmark using VS integrated Load Test project. There's one catch though, I need conditional logic. For example:
if Svc1 returns param1, then next requests should go to Svc2.
I'm using ExtractionRule
to extract the parameter from web API call, and if present, add that in Context and LoadTestUserContext
. Here's the code:
public override void Extract(object sender, ExtractionEventArgs e)
{
var serializer = new JsonNetSerializer();
var str = e.Response.BodyString;
var result = serializer.Deserialize<SpinResult>(str);
if (result.BonusRemainingTrials > 0)
{
e.WebTest.Context.Add("bonus", result.BonusRemainingTrials);
var userContext = (LoadTestUserContext)e.WebTest.Context["$LoadTestUserContext"];
userContext["bonus"] = result.BonusRemainingTrials;
e.Success = true;
}
}
and here's test conditional logic:
Everything works fine, until server returns the parameter, after which load test should invoke the second service (Svc2), which doesn't happen. No matter if "bonus" parameter assigned or not, the test always invokes Svc1. Any help why it's so stubborn?
Many thanks.