Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load performance testing with Gatling and Content-Type

I am using gatling for load performance testing on a brand new API. It seems fairly easy and well documented but I am facing an issue as simple as POST a request with Content-Type set to 'application/vnd.api+json' on the Header. All works well when doing the GET stuff but when launching a POST test I get a

HTTP response:
status=
415 Unsupported Media Type
headers= 
cache-control: [no-cache]
Content-Type: [application/vnd.api+json; charset=utf-8]
Date: [Fri, 08 Sep 2017 12:57:10 GMT]
Server: [nginx]
Vary: [Origin]
x-content-type-options: [nosniff]
x-frame-options: [SAMEORIGIN]
X-Request-Id: [ff993645-8e01-4689-82a8-2f0920e4f2a9]
x-runtime: [0.040662]
x-xss-protection: [1; mode=block]
Content-Length: [218]
Connection: [keep-alive]

body=
{"errors":[{"title":"Unsupported media type","detail":"All requests that create or update must use the 'application/vnd.api+json' Content-Type. This request specified 'application/json'.","code":"415","status":"415"}]}

Here is the scala code I am using for the http request:

object PostTokenGcm {
 val token = exec {
  http("TestAPI POST /tokens")
    .post("/tokens")
    .headers(Map("Authorization" -> testApiToken,
       "Content-Type" -> "application/vnd.api+json",
        "Accept" -> "application/vnd.api+json" ))
    .body(StringBody(gcmTokenRequestBody)).asJSON
    .check(status.is(201))
    .check(bodyString.exists)
}}

It seems that it is not setting the Content-Type?

Thank you for any lead!

like image 932
Sofia Avatar asked Sep 08 '17 14:09

Sofia


People also ask

Can Gatling be used for UI performance testing?

Gatling: Performance Testing ToolIt's is a quite famous and powerful open-source tool for performance/load testing and provides integration with CICD tools like Jenkins. It offers great reporting and an easy to use recorder and script generator. It provides default integration with build tools like Maven and Gradle.


1 Answers

In your POST definition you're using asJSON. According to notes in documentation about request headers:

http("foo").get("bar").asJSON is equivalent to:

http("foo").get("bar")
  .header(HttpHeaderNames.ContentType, HttpHeaderValues.ApplicationJson)
  .header(HttpHeaderNames.Accept, HttpHeaderValues.ApplicationJson)

... so, headers set in:

.headers(Map("Authorization" -> testApiToken,
       "Content-Type" -> "application/vnd.api+json",
        "Accept" -> "application/vnd.api+json" ))

... get overwritten by asJSON to "application/json" (which is the value of HttpHeaderValues.ApplicationJson).

like image 167
Eugene Loy Avatar answered Oct 22 '22 18:10

Eugene Loy