Karate: Feature Request: retry mechanism

Created on 15 Nov 2018  路  18Comments  路  Source: intuit/karate

The follow code can correctly run now:

Feature:
  Background:
  * url 'url'

  Scenario:
  * def input =
  """
  {
    'form': {},
    'query': {},
  }
  """
  * path '/rest/n/test'
  * params input.query
  * form fields input.form
  * method post
  * status 200
  * math response contains { result: 1 }
  * eval if (response.result != 1) karate.call('delete-user.feature'))

So, I hope hope retryPost method which can retry-post the scenario (it can auto check status).

or:

...
* eval if (responseStatus == 5xx) retryPost/retryGet/retryPut
* eval if (response.result != 1) retryPost/retryGet/retryPut

Here retryPost/retryGet/retryPut only re-run the section code.

for example:

Feature:
  Background:
  * url 'url'

  Scenario:
  # section 1
  ...
  * method post
  * eval if () retryPost # only re-run section 1

  # section 2
  ...
  * method post
  *eval if () retryPost # only re-run section 2

Thanks a lot!

enhancement fixed

All 18 comments

@thinkerou just to be sure I understand correctly

  • what do you want to re-try. is it the previous request ?
  • how many times should we re-try ?
  • what should be the delay time between re-tries ?

will this be OK:

* def done = function(){ return response.result == 1 }
* path '/rest/n/test'
* params input.query
* form fields input.form
* configure retryInterval = 3000
* retry post until done

@ptrthomas

  • yes, the previous request, not all request.
  • hope that user can set retry count, but it should have default value, for example: 3.
  • And also hope that use can set retry time, may be set default value better, for example: one seconds.

@thinkerou ok makes sense. I got another idea - so we don't change the method step

* configure retry = { interval: 1000, attempts: 3 }
* url foo
* path bar
* retry until responseStatus == 200 && response.myKey == 'someValue'
* method post

@ptrthomas thanks, look good to me 馃挴

@ptrthomas other idea: alert!

* configure retry = { interval: 1000, attempts: 3, callback: func() {} }
* url foo
* path bar
* retry until responseStatus == 200 && response.myKey == 'someValue'
* method post

when retry 3 times the case still fail, callback will be called.

Why need the callback? user can define one alert function and notify user.

@thinkerou thanks :) but then people will expect a callback for normal match also.

instead of this, you can use * configure afterScenario = function(){} to alert users. but normally I think this is too much complexity and no-one uses it ^_^

@ptrthomas because my team run online http request every 3min for monitor online interface(we found some valid alert), so I want to alert when only retry some times it still fail.
ok, I see afterScenario, thanks again.

@ptrthomas one question: how do afterScenario get responseStatus or response? because only retry some times still fail afterScenario is called(if the scenario is ok it will continue).

not sure I understand. if there is any failure in the test, karate.info.errorMessage will not be null

https://github.com/intuit/karate/blob/master/karate-demo/src/test/java/demo/hooks/hooks.feature

But have the follow scenario: I get the result list(includes 10 elements) from http server, when status=200 && the length of list != 10 will retry request, if all retry fail(len != 10), it should alert.

in my opinion, afterScenario and karate.info.errorMessage should work for this, try and see

@ptrthomas thanks, yes, afterScenario is ok.

Is this implemented yet? I tried it out on RC5 and it just did 1 try.

Ok, Im going to assume it is, will submit an issue, thanks :)

@76creates my apologies. I assumed you would have seen the (draft) release notes: https://github.com/intuit/karate/wiki/v0.9.0

yes this is in RC5 and I would appreciate more details on how to replcate !

0.9.0 released

@DevathaRaju please don't do this here and use stack overflow, thanks.

Was this page helpful?
0 / 5 - 0 ratings