HudsonHornet
HudsonHornet

Reputation: 89

gatling: respons body not saving when polling http request

I'm running stress test using gatling and java, so when i poll http request, response body not saving, but when i call http request directly from exec(getState) without poll() function, it saves. Here's my code:

    HttpRequestActionBuilder getState =
        http("Get state")
                .get(mainApiUrl + "/users/" + "#{" + INSTANCE_ID + "}")
                .header("Authorization", "Bearer " + "#{" + AUTH_TOKEN + "}")
                .check(status().is(200), jsonPath("$.metadata.frontendStatus").saveAs(FRONTEND_STATUS));


    ChainBuilder startRequest =
        feed(randomRequestBodyFeeder)
                .pause(1)
                .exec(authorize)
                .pause(Duration.ofSeconds(4))
                .exec(poll().every(Duration.ofSeconds(1)).exec(getState))
                .doIf(session -> session.getString(FRONTEND_STATUS).equals(WAITING_FOR_CUSTOMER_APPLICATION)).then(
                        exec(postApplication).pause(Duration.ofSeconds(5))
                ))
                .exec(poll().stop());

Upvotes: 0

Views: 333

Answers (1)

Stéphane LANDELLE
Stéphane LANDELLE

Reputation: 6623

Polling doesn't support checks atm. This was missing from the documentation. I just pushed a commit to mention it.

Then, I'm not sure what you're trying to achieve here.

poll works as a non-blocking background task.

It looks to me what you're trying to achieve is "as long as the request doesn't return some status, wait some time and try again", hence some blocking logic. This is something you should implement with a conditional loop such as asLongAs or doWhile, see https://gatling.io/docs/gatling/reference/current/core/scenario/#aslongas.

Upvotes: 2

Related Questions