Measure response time of async call

I am testing an application that has an async call. I send a message to ActiveMq via Gatling and I need to check the results in an async way.

The check can be done in by verifying a file exists in aws s3 bucket

My scenario looks like this:

al scn: ScenarioBuilder = scenario("Report generation")
  .feed(baseFeeder)
  .exec(triggerReport)
  .group("Wait for file to be generated") {
    asLongAs(session => !notGenerated(session))(
      pause(1)
      .exec(session => pollGeneratedReportAWS(session))
    )
  }
  private def pollGeneratedReportAWS(session: Session): Session = {
    try {
      val credentials: InstanceProfileCredentialsProvider = InstanceProfileCredentialsProvider.createAsyncRefreshingProvider(true)
      val s3: AmazonS3 = AmazonS3ClientBuilder.standard.withRegion(Regions.EU_WEST_1).withCredentials(credentials).build
      val keyName: String = "name"
      val o: S3Object = s3.getObject("bucket", keyName)
      val content: S3ObjectInputStream = o.getObjectContent
      val fos = new FileOutputStream(new File(keyName))
      val read_buf = new Array[Byte](1024)
      var read_len = 0
      while ((read_len = content.read(read_buf)) > 0) {
        fos.write(read_buf, 0, read_len)
      }
      content.close()
      fos.close()
      session.set("successful", true)
    } catch {
      case _: Throwable => session.set("successful", false)
    }
  }

I want to measure how long does it take for the file to be published in aws but the problem is that in the report the exec that I have in my code is not reported.
Do you know how can i include in the report the custom exec block that i wrote?

Simulation file looks like this

RUN	perf.gatling.transactionexporter.simulations.TriggerSimulation	triggersimulation	1648117671430	 	3.7.5
USER	Report generation	START	1648117672148
REQUEST		Send Report Trigger	1648117672200	1648117672215	OK	 
GROUP	Wait for file to be generated	1648117672218	1648117673240	0	OK
USER	Report generation	END	1648117673242

But the Wait for file to be generated exec isn’t present in the report generated.

Wrap your whole sequence with a group.

Wow, such a simple solution :dizzy_face:

1 Like