Search code examples
javaload-testinggatling

Gatling HttpProtocolBuilder sign request with auth header for each request


As aws auth signatures are expiring in 5 mins, i would like to refresh auth headers for long running tests, either for every less than 5 mins or for each request, i tried http.sign method, but it does not get invoked for some reason

here is how the code looks

HttpProtocolBuilder httpProtocol = LoadTestHelper.getHttpProtocolBuilder(ENDPOINT);
String payload = "JSON payload";
ScenarioBuilder users = scenario("Users").exec(http("initiation").post(ENDPOINT).headers(getAuthHeaders()).body(StringBody(payload)).check(status().is(200)));
users.injectOpen(rampUsersPerSec(1).to(LOAD_USERS).during(Duration.ofSeconds(LOAD_DURATION)))

Solution

  • sign method works fine,i was applying sign with HttpProtocolBuilder, but it supposed to be http in ScenariooBuilder, the syntax is something like this

      ScenarioBuilder users = scenario("Users").exec(http("initiation").post(ENDPOINT).sign(request -> {
            Map<String, String> headers = LoadTestHelper.getAuthHeaders();
    
            for (Map.Entry<String,String> entry : headers.entrySet())
            {
                request.getHeaders().add(entry.getKey(), entry.getValue());
            }
        }).body(StringBody(payload)).check(status().is(200)));