1

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:

enter image description here

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.

Hossein Narimani Rad
  • 31,361
  • 18
  • 86
  • 116
Davita
  • 8,928
  • 14
  • 67
  • 119
  • Do you use unit tests for load testing? Or where do you check if the parameter you put to the TestLoadContext? If you use Unit tests, do you pass the load test context parameter to your unit test appropriately? http://blogs.msdn.com/b/slumley/archive/2006/12/15/passing-load-test-context-parameters-to-unit-tests.aspx – Legends Apr 08 '15 at 20:07
  • @Legends It's not standard unit test. It's load test. The parameter is being checked in webtest, see image above. – Davita Apr 08 '15 at 20:12
  • 1
    So, the parameter is returned by the server. Why don't you generate code for your webtest and debug it? – Legends Apr 08 '15 at 20:29
  • Any idea how to debug generated code without moving to external project..? Thanks :) – Davita Apr 08 '15 at 22:19
  • Just found it, Right click -> Run Coded Web Performance Test – Davita Apr 08 '15 at 22:21
  • You wrote "*No matter if "bonus" parameter assigned or not*". There is a difference between "assigned" and "exists". You might add requests before, between and after the two conditionals, the URL it not important, it could be "example.com". Then in the web test results view the context tab looking for "bonus" in these 3 new requests. – AdrianHHH Apr 09 '15 at 11:13
  • @AdrianHHH I see, but "bonus" parameter is correctly assigned, I debug token extractor but the test still invokes the first service when it should invoke the second one. I'm really confused :( – Davita Apr 10 '15 at 15:04
  • Again, there is a difference between "*assigned*" and "*exists*". The webtest conditional checks for the existence of "bonus", not for its value. What is shown for "bonus" in the three requests I suggested adding? You need to provide much more information in your question to get much further help. – AdrianHHH Apr 10 '15 at 15:26
  • Your code has `e.WebTest.Context.Add("bonus", ...);` whereas normally an extraction rule would have `e.WebTest.Context.Add(this.ContextParameterName, ...);`, so it writes to the context parameter passed as a parameter (ie a property) to the plugin – AdrianHHH Apr 10 '15 at 15:28
  • @AdrianHHH nope, didn't help... – Davita Apr 10 '15 at 15:41
  • What did not help? You need to provide more information in the question. – AdrianHHH Apr 10 '15 at 16:17
  • e.WebTest.Context.Add(this.ContextParameterName, ...); <-- this I mean. What information is missing from my post..? :) – Davita Apr 10 '15 at 16:18
  • What is missing is the information that will let us help you. I have suggested some debugging ideas, you have not described what they showed and what you learned from that. You have not shown any logging details from running the tests. You write "*nope, didn't help*" without saying what did not help. Please read http://stackoverflow.com/help/mcve then consider rewriting your question with enough detail so we can try and reproduce the problem you are seeing. – AdrianHHH Apr 11 '15 at 13:14
  • Bounties often attract several answers, but in several days no one has offered any suggestions on this question. Perhaps they all agree with me that more information is required. I am happy to try and help with your question, so please add more details of what is happening, what debugging results you have and any other useful information that will help us to help you. – AdrianHHH Apr 15 '15 at 09:07
  • Thanks @AdrianHHH. Unfortunately, it is not possible for me to debug services without some code changes on service side. I'm still waiting for the code of the services and will try to debug it. Though I think it's redundant, because extraction classes correctly extracts the branching parameter and adds in the context. It's "If" that's not working... – Davita Apr 15 '15 at 10:02

0 Answers0