Forum Discussion

spsuser's avatar
spsuser
Occasional Contributor
11 years ago

Property reset of TestRequest on TimeOut

Hello,
I am using a Test Suite in SoapUI Pro 4.5.1 (4.5.2 shows same behaviour).

Scenario:
I am reading properties from a excel based data source, create a TestRequest with the properties and write elements of interest in a excel based datasink (and loop)

Works as expected except for one case:
If a TestRequest step runs into a "java.net.SocketTimeoutException: Read timed out" the following datasink test step writes the data of the last working TestRequest step into the datasink.
That's a bit annoying as it looks in the Excel like it worked properly.

I experienced the behaviour as well with a groovy teststep where I read the "Time Taken" from the response
def Dauer = testRunner.testCase.testSteps["Test Request"].testRequest.response.timeTaken;

Does anybody know how to null/reset/clean the Response and its properties in this case?

9 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    Could you try to add an assertion test step right after your request testStep to make sure that it returned correctly before you actually write anything into your datasink?

    Regards,

    Renato Athaydes
    SmartBear Software
  • spsuser's avatar
    spsuser
    Occasional Contributor
    Hi,

    I assigned a Assertion TestStep which checks the response of the request test step against valid http response codes (here 200).
    But the result in the data sink is the same.
    Did you mean sth. different?
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    If the assertion fails, then the next test-step will not run, ensuring that the incorrect value is not written to your data-sink.

    If what you want, instead, is to ensure you write an error into the data-sink when the response code is not 200, you may write a simple Groovy script testStep as follows:

    def resp = testRunner.testCase.testSteps[ "Test Request" ].testRequest.response
    def val = ( resp.statusCode == 200 ) ? resp.responseContent : "FAIL"

    testRunner.testCase.setPropertyValue( "response1", val )


    This will set the value of property "response1" in the TestCase to either "FAIL" or the actual response returned by the server.
    To write this property to your data-sink, add a data-sink property with the following value, without quotes: "${#TestCase#response1}"

    Let me know if this helped,

    Renato Athaydes
    SmartBear Software
  • spsuser's avatar
    spsuser
    Occasional Contributor
    Sorry for answering late but your forum didn't reminded me of your post.

    Actually I want the DataSink to write the result of this step.
    I have several properties in a property transfer test step. They get me a value via xpath from the response and write it to the according datasink property.
    I hoped a "set null on missing source" would help. (It works for "normal" result where xpath simply doesn't resolve) But for timeout somehow it keeps the last working response value.

    I adapted your code a bit and tried

    def resp = testRunner.testCase.testSteps[ "Test Request" ].testRequest.response
    if ( resp.statusCode != 200 )
    {
    testRunner.testCase.testSteps[ "DataSink" ].setPropertyValue( "Status", resp.statusCode )
    }
    testRunner.testCase.testSteps[ "DataSink" ].setPropertyValue( "Status", resp.statusCode )


    The last line I added as the "if" never triggers to true. The statusCode for this script is still 200. Even in case of timeout.
    So a check on statusCode doesn't help me to trigger the error case in my script.

    Any further ideas? Thanks in advance
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi again,

    Sorry for the delay... I also do not get notified when you answer

    Well, I have tried the following scenario:

    - Run a REST TestStep
    - Run a Groovy TestStep with the following script:
    def resp = testRunner.testCase.testSteps[ "Test Request" ].testRequest.response
    def val = ( resp?.statusCode == 200 ) ? resp.responseContent : "FAIL"

    testRunner.testCase.setPropertyValue( "response1", val )

    - Run a DataSink TestStep to write the value of "response1" to a file.

    NOTE: I added a question mark in the if condition resp?.statusCode == 200 so that if the response is null, as in when there's a timeout, Groovy will evaluate the expression to false.
    I UNselected "Abort on Error" in the TestCase Options (click on the TestStep Editor's toolbox icon) to ensure the other test steps will always run regardless of whether the Test Request TestStep fails.

    Everything worked as expected... when the Request fails with a SocketTimeoutException, The value of the property is set to "FAIL" by the Groovy script and then written to the data-sink. If the request succeeds, the response is written to the data-sink.

    Could you please check if this scenario works for you? I believe this would solve your problem.

    Best regards,

    Renato
    SmartBear Software
  • spsuser's avatar
    spsuser
    Occasional Contributor
    Hello,

    unfortunately not. I simply face the problem that the response object isn't reset/deleted in case of "SoapUI Timeout".
    Maybe this is a missing fact for your research. The timeout is triggered by SoapUI not the Webservice.
    My SoapUI is set to 60 sec. To force and test this in my case I set the timeout in the Test Request step to 4 sec. This leads to the "-> java.net.SocketTimeoutException: Read timed out".

    I again slightly adapted your code as I don't want the whole response in an excel cell.

    def resp = testRunner.testCase.testSteps[ "Test Request" ].testRequest.response
    def val = ( resp?.statusCode == 200 ) ? "OK" : "TIMEOUT"

    testRunner.testCase.testSteps["DataSink"].setPropertyValue("Status", val);

    And this still returns OK when I experience the above SocketTimeoutException.
    So either this is a bug or I need another object/message/property where the TimeoutException for this test step is stored to be read out.

    Best regards
  • spsuser's avatar
    spsuser
    Occasional Contributor
    Hi,
    that doesn't help either. On timeout the following test steps after test request still read from the last working response.
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    I am sorry but all I can tell you is that I have run the test steps as mentioned in my previous response and it worked as expected.

    I let SoapUI timeout (which causes a SocketTimeoutException) so that my script would get "response" as a null object, which causes the script to write "FAIL" to the datasink.

    I would advise you to start a new, very simple project with just one request, follow the instructions given above and make some small tests for yourself.

    Notice that my tests were run with SoapUI 4.5.2.

    If it still does not work, please send us the project and we will try to reproduce the problem.

    Regards,

    Renato
    SmartBear Software