Test Scenarios - How to poll for updates

(Matt) #1

Hi guys,
We have an asynchronous update scenario and want to this it. In the scenario, we request the change of a record. This might take a few seconds and we don’t now how long. Eventually, it will be updated.
The first response we get is instant and tells us that the update is in progress. This can be described in a test case and is straightforward.
The next calls would be a kind of polling. We need to keep calling an endpoint until the update is completed. This might be 1 call only, or might be 5 calls. The things is we don’t know initially how many time we need to make this call.
In JMeter this is pretty straightforward to implement and test with a while loop. Unfortunately, I did not find any way to test this in Stoplight. Does anyone have any idea how to create a test for such a scenario?

(Ross McDonald) #2

Hi @matt,

Unfortunately I don’t think we have a good solution for this right now. Prism steps can “sleep” for a specified amount of time, however there isn’t a way to continuously loop and poll like you’re needing in this case.

Do you have an approximate upper-bound on the amount of time the action usually takes? As part of your scenario, you could always sleep for that amount of time (30s, 60s, etc). This is obviously not an ideal solution, but it would allow you to continue with the rest of the Scenario.

(Matt) #3

Hi @ross,

Thanks for the feedback. As a workaround we have added a before script.

var ms = 5000;
var start = new Date().getTime();
var end = start;
while(end < start + ms) {
   end = new Date().getTime();

A helpful extension for the future might be the possibility to specify max attempts for making the API call and get a positive result.

(Erik Hansen) #4

I second the addition of a retry mechanism on a specified step or sequence. I haven’t done this level of testing yet, but I think it’s coming soon! :grimacing:

(Taylor Barnett) #5

Thanks for sharing that, @matt! I’ll make sure we have something added as an enhancement for this.