olibur
olibur

Reputation: 377

Karate 0.9.5.RC5 - 'retry until' function somehow does not respect my 'retry' configuration in karate-config.js

I have following test:

Feature: News API

  Background:
    * url baseUrl

  Scenario: get news index
    Given path "/"
    And retry until responseStatus == 200
    When method get
    Then status 200
    And match response contains "News service up and running"

and the following karate-config.js

function fn() {
    // get java system property 'karate.env'
    var env = karate.env;
    karate.log('karate.env system property was:', env);

    var config = {
        baseUrl: 'http://localhost:8080',
    };

    karate.configure('retry', {count: 5, interval: 6000});
    karate.configure('connectTimeout', 5000);
    karate.configure('readTimeout', 5000);

    return config;
}

and the following error in the console after executing the tests with the maven-failsafe-plugin:

...
[INFO] Running newsservice.NewsServiceIT
[main] INFO  o.a.http.impl.execchain.RetryExec - I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}->http://localhost:8080: The target server failed to respond
[main] INFO  o.a.http.impl.execchain.RetryExec - Retrying request to {}->http://localhost:8080
[main] INFO  o.a.http.impl.execchain.RetryExec - I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}->http://localhost:8080: The target server failed to respond
[main] INFO  o.a.http.impl.execchain.RetryExec - Retrying request to {}->http://localhost:8080
[main] INFO  o.a.http.impl.execchain.RetryExec - I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}->http://localhost:8080: The target server failed to respond
[main] INFO  o.a.http.impl.execchain.RetryExec - Retrying request to {}->http://localhost:8080
[main] ERROR com.intuit.karate - org.apache.http.NoHttpResponseException: localhost:8080 failed to respond, http call failed after 2 milliseconds for URL: http://localhost:8080/
[main] ERROR com.intuit.karate - http request failed: 
org.apache.http.NoHttpResponseException: localhost:8080 failed to respond
---------------------------------------------------------
feature: classpath:newsservice/news/news-index.feature
scenarios:  1 | passed:  0 | failed:  1 | time: 0.7678
---------------------------------------------------------

HTML report: (paste into browser to view) | Karate version: 0.9.5.RC5
...

Before the tests start, I boot up my Spring Boot application and this takes some time (~5-7 seconds) and I know that the test does not succeed because the Sprint Boot app has not yet started.

That's why I've tried to use this retry until feature of Karate to make sure it retries after some intervals.

But it seems that the retry config is not respected according to the console output. It seems so that it always only try 3 times...

I have also tried to set the retry config in the test file itself like in the Karate docs with:

* configure retry = { count: 10, interval: 5000 }

but this also did not work.

Maybe you have a hint why it does not work or do I still miss something?

Upvotes: 2

Views: 1206

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58128

The problem is retry until comes into the picture only after the HTTP connection has been established. You need to figure out a way to wait until your server can accept connections.

Why you see 3 attempts is because that is the default behavior of the underlying Apache HTTP client.

You should be able to write or re-use some utility to do this. Take a look at this code from Karate internals, look for the waitForHttp method:

https://github.com/karatelabs/karate/blob/v1.4.1/karate-core/src/main/java/com/intuit/karate/shell/Command.java#L219

And in my opinion, the best place to do this "wait" is in the JUnit / Java code that kicks off the Karate suite - which you probably already have for starting Spring Boot.

Upvotes: 1

Related Questions