'Karate retry mechanism for SocketTimeoutException

We have a system that we use in order to make some PUT requests during tests. The issue is that this system has, at the moment, some issues with its resources and sometimes it can't answer in time. We can't increase the read timeout to a value greater than 60 seconds for 2 reasons: if the system doesn't answer fast it most likely won't answer at all and secondly we're using a proxy which times out at 60 seconds.

I'm aware of this question , but waitForHttp or waitForPort don't fit our requirements as the port is available and there is no health endpoint telling us if the PUT request will succeed or just be lost.

Is there anything else we can do?

Example feature:

  Background:
    * url dep_url
    * configure headers = read('classpath:package/headers/headers.json')
    * retry until responseStatus !== 429

  Scenario: Create entity
    Given request read('classpath:package/body/' + file)
    When path '/entity/' + entity[index]
    And method put
    Then assert responseStatus == 200 || responseStatus == 201

We need retries when a SocketTimeoutException is thrown, for example:

java.net.SocketTimeoutException: Read timed out, http call failed after 253 milliseconds for url


Solution 1:[1]

Well, try polling then: https://stackoverflow.com/a/56799845/143475

And combine that approach with the fact that you can use a JS try-catch in Karate: https://stackoverflow.com/a/67024149/143475

So maybe something like this:

* def failed = false
* eval try { karate.call('called.feature') } catch (e) { karate.set('failed', true) }

You should be able to figure out a solution now. Do post what you come up with.

EDIT: for those who feel bad about calling a second feature file, you can do everything in one file like this:

Feature:

Scenario:
* call read('@called')

@ignore @called
Scenario:
* print 'called'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1