Service Virtualization

  • 1.  How to execute a particular step for fixed duration of time

    Posted Oct 29, 2018 02:48 AM

    Hi All

     

    I have a scenario where in I need to hit a particular request multiple times and fetch a response.But if the time duration is more than 2 minutes then I need to move to the next step.

     

    Please help out with the approach that can be followed

     

    Regards

    Yugain



  • 2.  Re: How to execute a particular step for fixed duration of time

    Broadcom Employee
    Posted Oct 29, 2018 02:56 AM

    The first option to look at would be to use the time out mechanism of the technology that you are using.

    What is that technology? HTTP? Message queues?

    And once you have set the timeout value to 120 seconds then you can adjust the standard “Environment Error” assertion that is part of the calling step and instead of letting it fail the test, you can go to a step where you test if the environment error was a timeout, if so go to next step, if not then fail the test.

     

    Cheers,

    Danny



  • 3.  Re: How to execute a particular step for fixed duration of time

    Posted Oct 29, 2018 03:06 AM

    Hi Danny

    Iam hitting the request using a Rest Step.

     

    How can I set up the timeout value as 120 second in CA devtest 10.2.4

     

    Regards

    Yugain



  • 4.  Re: How to execute a particular step for fixed duration of time

    Broadcom Employee
    Posted Oct 29, 2018 05:28 AM

    Yes, the Web Service call has a timeOut field (in the PRO options) but the REST step has not. You will have to adjust the lisa.http.timeout.connection and set it to 120000 milliseconds. Snippet from the DevTest documentation:

     

       

    •   lisa.http.timeout.connection

    HTTP timeout (in milliseconds) - To extend the timeout to wait indefinitely, set the values to zero.

    Default: 15000

     

    If you are testing this from your workstation then edit your local.properties file and add:

     

    lisa.http.timeout.connection=120000

     

    Then restart your workstation and test.

     

    Obviously the side-effect of changing local.properties is that now all your http calls will have this time out. So, as soon as you have validated that this property allows you to implement your requirement, BUT for actual testing you only want this testcase to have this time-out value then you can think of adding an execute script step before the REST step and add:

     

    testExec.setStateValue("lisa.http.timeout.connection",120000);

     

    And take the line out of local.properties so that it defaults back to 15 seconds.

     

    Cheers,

    Danny



  • 5.  Re: How to execute a particular step for fixed duration of time

    Posted Oct 29, 2018 09:50 AM

    Hi Danny

     

    thanx for your response.

     

    I have below question:

    1.Will the script  "testExec.setStateValue("lisa.http.timeout.connection",120000);" work only if I don't get the response.

     

    Scenario under Test:

    1.Hit a Rest request and get payment status

    2.If payment status comes D stop the test cases

    3.if payment status comes other then D,then again hit the same request and keep on doing the same for maximum 2 minutes.

     

    Approach Followed:

    1.Created Excecute Script (JSR-223) step with below snippet:

    "testExec.setStateValue("lisa.http.timeout.connection",120000);"

    2.Hit the Rest Request to get the payment Status.

    3.The Rest request has an assertion wherein we check if payment status is not equal to "D" then again hit the Rest request.

    4.We need to do step 3 for max of 2 min. If after 2 minutes also the payment status is not D then we will move to next step.

     

    Regards

    Yugain



  • 6.  Re: How to execute a particular step for fixed duration of time

    Broadcom Employee
    Posted Oct 29, 2018 11:11 AM

    Hi,

     

    Here’s what setting the connection timeout to 120 seconds will do.

     

    You have a REST step (synchronous call) that starts execution, it sends a request, and now starts waiting for a response:

     

       

    •   Between 0 and 120 seconds the following can happen

          

    •   Your system under test sends a proper response, the step will now continue by executing the defined filters, followed by executing the defined assertions.

          

    •   The step might end with an environment error, e.g. connection refused if there is nothing listening on the port

             

    •   This will trigger the “Environment Error” assertion and from the error code and or properties you will have to find out what it is

       

    •   At 120 seconds

          

    •   The step will end with an environment error, i.e. a connection timeout

             

    •   This will trigger the “Environment Error” assertion and from the error code and or properties you will have to find out if this was a timeout or if it was a different kind of environment error

     

    Cheers,

    Danny



  • 7.  Re: How to execute a particular step for fixed duration of time

    Broadcom Employee
    Posted Oct 29, 2018 11:53 AM

    I think you can use "Time Stamp filter" and create properties for Pre and Post process in your REST step. Then calculate the time difference in a Scripted assertion and also validate your response (need to write code) and return True/False.

     

    Time Stamp Filter - DevTest Solutions - 10.4 - CA Technologies Documentation 

    Scripted Assertion - DevTest Solutions - 10.4 - CA Technologies Documentation 



  • 8.  Re: How to execute a particular step for fixed duration of time

    Broadcom Employee
    Posted Oct 29, 2018 11:53 AM

    I think you need to ignore my remarks about the connection timeout, I now understand when you referred to 2 minutes it is not how long it can take before the response can come.

    It is about how long you want to keep polling the service if no "D" status is responded.

     

    You will have to build a loop over your rest step,

    • Before the loop you take a timestamp and store it in a property "startLoopTS"
    • Inside the loop you do the REST CALL
      • A filter (post process) to get the current timestamp, store it in a property "currentTS
      • An assertion to test if the status is "D", if true then the assertion will go to the continuation of the test
      • An assertion to test if the status is different from "S" (sent) as this would mean something unexpected in the SUT, if true then the assertion will fail the test
      • A scripted assertion
        • I have given the jave code to retrieve time stamp properties and then calculate the number of seconds between them
        • If delta of seconds is greater than 120, return "false", if false the assertion will fail the test
        • else return true
    • The REST call will loop onto itself, i.e. the next is "REST CALL"

     

    Hope this helps,

     

    Cheers,

    Danny