Forum Discussion

M_McDonald's avatar
M_McDonald
Super Contributor
16 years ago

Handling asynchronous responses in test cases

In a test case I call a service which responds immediately with an order number, but then later will make a callback to a URL to provide further details. I can use a Mock Service to intercept the callback in the OnRequest event when there is only one order being processed, but normally there are multiple orders being processed at any one time so I may intercept the callback for a different order.

What I am looking for is a technique that would allow the test case to "register" the order number with the Mock Service, then suspend itself until the matching callback was received by the Mock Service, which would then pass back the infomation received in the callback request to the appropriate test case and cause it to resume execution. This would allow testing in a busy environment and also parallel execution and load testing of this service.

Any suggestions?

1 Reply

  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    OK, I came up with something I think is workable.

    After the initial request step, I have Groovy step that adds a property to the Mock Service with a name containing the order number and an empty value. The script then goes into a loop in which it sleeps for a while, then checks to see if the value has been populated.

    When the Mock Service receives a callback request, in the OnRequest event it extracts the order number, then checks to see if there is a property with a matching name; if there is it fills in the value with the necessary info.

    When the script sees the property has been populated, the loop terminates, the info is copied from the Mock Service property, the property is removed from the Mock Service and the test case resumes execution.