0

I recently took some interest in learning some load testing tools and Gatling seemed a very good choice. The only drawback related to other tools is the lack of documentation/examples for the upload of files with dynamic values.

For example, to upload a static CSV file I can use:

val scn: ScenarioBuilder = scenario("My First Test")
.exec(http("Upload CSV")
  .post("/csv-upload")
  .formUpload("file", "file.csv")
  .check(status.is(202))
)

But if I want to add a feeder to add values to that CSV I would like to have something like:

val scn: ScenarioBuilder = scenario("My First Test")
.feed(customFeeder)
.exec(http("Upload CSV")
  .post("/csv-upload")
  .formUpload("file", ElFileBody("file.csv"))
  .check(status.is(202))
)

I already tried multiple methods to upload body parts and for example, if I do something of the sort:

val scn: ScenarioBuilder = scenario("My First Test")
.feed(customFeeder)
.exec(http("Upload CSV")
  .post("/csv-upload")
  .bodyPart(ElFileBodyPart("file", "file.csv"))
  .check(status.is(202))
)

I get an error on the server-side: MissingServletRequestPartException: Required request part 'file' is not present

I was able to proxy the request that Gatling does and the generated curl request is:

curl --location --request POST 'http://localhost:8080/api/v1/resource/csv' \
--header 'accept: application/json' \
--header 'content-length: 310' \
--header 'content-type: multipart/form-data; boundary=UhyANQVVCm0hahnV9JvGEA8tPLU1Kc2Z5Fj' \
--header 'host: localhost:8080' \
--header 'x-tenantid: t1' \
--data-raw '--UhyANQVVCm0hahnV9JvGEA8tPLU1Kc2Z5Fj
Content-Disposition: form-data; name="file"
Content-Type: multipart/form-data; charset=UTF-8

Name,Phone,Address
PersonName,123456,ThatStreet

--UhyANQVVCm0hahnV9JvGEA8tPLU1Kc2Z5Fj--
'

Which constructs the request correctly, but the error on the server side remains.

Is there any way that this can be achievable?

  • Have you tried having your custom feeder return a `List[Map[String, String]]` e.g. `List[Map("lines" -> "HelloWorld"]]` and in the `file.csv`, reference the key with `${lines}` ? – ccheneson May 26 '21 at 14:22
  • Yes, @ccheneson. The problem with that is that `formUpload` receives the filePath only, so I cannot have the ElFileBody in the formUpload, because it will return the file content and not the filePath to be used by the method – Ricardo Correia May 26 '21 at 14:44
  • Maybe you can add the lines from within your customFeeder function and save the file. Probably not efficient - or generate test files before executing request – ccheneson May 26 '21 at 14:52

1 Answers1

0

The only drawback related to other tools is the upload of files with dynamic values.

No idea where this comes from.

.formUpload("name", "path") is merely a handy shortcut for bodyPart(RawFileBodyPart("name", "path")).

Please read the official documentation regarding multipart support.

Stéphane LANDELLE
  • 6,076
  • 2
  • 10
  • 12