Validations over multiple requests

Hello,

I’m trying to have a simulation pass/succeed based on a result that is aggregated from multiple requests but I’m not sure how to do this.

For example, I’m running:
val products = ArrayBuffer[Integer]

.exec(loginHttpBuilder(username, password)
.check(status.is(200)))
.repeat(5) {

exec(getRecommendationHttpBuilder()
.check(status.is(200))
.check(jsonPath("$recommendation.productId").saveAs(“productId”))
)

.exec((session: Session) => {
val productId = session.attributes(“productId”).asInstanceOf[String].toInt
products.append(productId)

session

})
}

I want to assert that I only got the same product Id once. I’ve tried chaining the following which produces an error statement but does not result in execution failure:

.exec((session: Session) => {
val productMap = products.groupBy { identity }
if (productMap.values.find(_.size > 1).isDefined) Failure(s"Validation failed: ${productMap}") else session
})

How should I go about performing this validation?

Thanks,
Laurent

If I get it right, you’re trying to use Gatling for integration testing. Right?

You have to log a fake request with a KO status and then use the assertion API.

Which version of Gatling do you use?

That’s right.

I’m using Gatling 2.0.0-M3a. I’ll try out your suggestion. Thanks!

Here’s the kind of stuff you’d have to do in order to log a fake request: https://github.com/excilys/gatling/blob/2.0.0-M3a/gatling-http/src/main/scala/io/gatling/http/ahc/AsyncHandlerActor.scala#L101

Note that your ArrayBuffer is not threadsafe.

Thanks. I fixed the thread-safety issues (pulled the variables into the session). This seems to meet my current needs.

Will this sort of integration test validation be a little more ‘built-in’ in the future or will faking a request be the only way?

Thanks. I fixed the thread-safety issues (pulled the variables into the
session). This seems to meet my current needs.

Glad to hear.

Will this sort of integration test validation be a little more 'built-in'
in the future or will faking a request be the only way?

Can't tell for now. It depends if we have enough community feedback in this
direction.