How to stop injection when host name or port is incorrect

Hello,
i have a question please:
i noticed that when i start injection and if for example the port target or the host name target is incorrect, i get (Connection refused: no further information…), and that is very normal, but why the test don’t stop (infinite loop errors)?
every time i have to stop engine by hand, i would like to know if there is a way to add some functions in my script to say if for example connection refused stop injection !!!
Thanks

You can use exitBlockOnFail to terminate a virtual user when it fails. But there is not an established way of short-circuiting the injection profile.

There may be a hack-ish way of doing it, but . . . don’t. Do not clutter your script with logic whose sole purpose is to make it so you don’t have to press Ctrl-C when you feed it the wrong parameters.

What you should be doing is be certain that your test is using the right parameters before you start it.

What you can do is have two different simulations that use the same scenario. One injects exactly one user, and the other does the full injection profile. Run the single-user version, and if that works, you know you are good to start the longer-running simulation. I do this often, and so I have boilerplate code to make it quick and easy:

// define that an object/class describes how a virtual user behaves
trait UserBehavior {

def behavior: ScenarioBuilder
}

// define a specific scenario
object UserThatDoesXYZ extends UserBehavior {
def behavior = scenario(“XYZ”) // …
}

// define the single-user case
class VerifyXYZ extends UnitTest {
def behavior = UserThatDoesXYZ.behavior
}

// define a ramp test that uses config values to control its behavior
class TestXYZ extends OpenRampTest {
def behavior = UserThatDoesXYZ.behavior
}

// for reference, here is UnitTest:
trait UnitTest extends Simulation {
def http_config = Default.httpConfig
def behavior : ScenarioBuilder

setUp( behavior.inject( atOnceUsers(1) ) )
.protocols( http_config )
.pauses( if( Test.usePauses ) exponentialPauses else disablePauses )
.assertions( global.failedRequests.count.is(0) )
}

// and OpenRampTest is similar:
trait OpenRampTest extends Simulation {
def http_config = Default.httpConfig
def behavior : ScenarioBuilder

val from = if ( Test.min_users > 0 ) Test.min_users else 1.0 / 3600.0
val to = Test.users * Test.multiplier // per second

setUp(
behavior
.inject(
rampUsersPerSec( from ) to ( to ) during ( Test.rampUpTime )
constantUsersPerSec ( to ) during ( Test.duration )
rampUsersPerSec( to ) to ( 0 ) during ( Test.rampDownTime )
)
.protocols( http_config )
.pauses( if( Test.usePauses ) exponentialPauses else disablePauses )
.maxDuration( Test.rampUpTime + Test.duration + Test.rampDownTime + 300 )
}

All of this boilerplate code is freely available on GitHub: https://github.com/JohnArrowwood/gatling-common
And a seed project that shows how to incorporate it is here: https://github.com/JohnArrowwood/gatling-sbt-seed

Thanks for your replay, i do not want to stop the VUs when some injection fail (because i know the injection will stop after some few minutes using for example //rampUsersPerSec(tps_min) to (tps_max) during (duration second)
or //constantUsersPerSec(2) during (1 minutes)… ),

but what i want to do is to stop Engine when something happen like if the Port or Host name target are incorrect (so in this case there is no injection because the connection is refused, that’s why i get infinite loop errors),
i use jenkins for starting the simulation, so i don’t have access to stop button, actually i use timeout in Jenkins to stop test but i think its better to do some code to stop test (some thing like exitHereIfFailed)

It’s not possible with Gatling OSS but panic criteria are in FrontLine’s roadmap.