doIfOrElse does not execute any of the branches

I am trying to do this:

foreach("${foo}", “x”) {
.doIfOrElse(.getVSeq[String].map(.contains("${x}"))) {
chainA
} {
chainB
}
}

However, this causes neither chainA nor chainB to be run. I’m assuming the validation fails, but I’m not getting any error messages. I’m using 2.0-M1. Does anyone know what could be going on here? Should I try again with (what will be) M2?

Stig

I’d always expect chainB as your condition can’t evaluate to true.

You can’t use EL inside Expressions. EL are actually implicitly compiled into expressions where required, and contains expect a String, not an Expression.

The safe form is:

foreach("${foo}", “x”) {
doIfOrElse{ session =>
for {
bar ← session.getVSeq[String]
x ← session.getVString
} yield (bar.contains(x))
}
{chainA}
{chainB}
}

The unsafe one:

foreach("${foo}", “x”) {
doIfOrElse{ session =>
val bar = session(“bar”).asInstanceOf[Seq[String]]
val x = session(“x”).asInstanceOf[String]
bar.contains(x)
}
{chainA}
{chainB}
}

I’ll investigate to see if I see a reason why chainB wouldn’t be executed, but that might come from the way you wrote it.

This is now my new favourite support forum :slight_smile:
Three right-to-the-point answers in one day - thanks a lot!

Stig

You’re welcome.

BTW, there was indeed a bug in 2.0.0-M1 and chainB was indeed ignored.
https://github.com/excilys/gatling/issues/1136

Fixed, thanks for reporting!