Timestamp Gatling

Hi,

I’m trying to get an unique email for each of my created user with Gatling.
So when i create the user I use this function:

def emailUnique(email: String): String = {
var emailUnique = “testGatling” + “+” + System.currentTimeMillis+ “@example.com

return emailUnique
}

When my first user is created he got this email : testGatling+292843029197921@example.com BUT
when my second user is created he got the same email: testGatling+292843029197921@example.com

The timestamp has not change between the two users. Here’s my simulation:

setUp(
ProvisioningUser.scn.inject(
atOnceUsers(1),
nothingFor(4 seconds),
atOnceUsers(1)
).protocols(httpConf)
)

Why the timestamp did not change ? Or how can I’ve got unique email every time (without clear the database) ?

Use a UUID.

My2cents: you’re calling emailUnique directly instead of calling it from a function, so it’s only called once.

I try with UUID but i’ve got exactly the same issue, the two users have the same UUID.

I think it’s about what Stéphane say but I don’t understand your Answer Stéphane. Why my function is called once ? How can i do ?

Call you show the way you're using your emailUnique method, please?

Maybe I’ve got an idea. How can I store a static variable for all my users ? A variable starting to System.currentTimeMillis and I will increment each time a user is created ?

/**

  • Provision the base with a new user base on user_provisioning feeder
  • param access_token_basic
  • return access_token Auth token for the created user
    */
    val provisioning = exec().feed(provisioningUsers)
    .exec(http(“Create a new user”)
    .post("/users")
    .header(“Content-Type”, “application/json”)
    .header(“Authorization”, “Bearer ${access_token_basic}”)
    .body(StringBody("""{“login”: “”"" + emailUnique("${login}") + “”"", “password”: “${password}”, “user”: {“firstname”: “${firstname}”, “lastname”: “${lastname}”, “gender”: “${gender}”, “locale”: “${locale}”, “country”: {“code”: “${country_code}”}, “facebookID”: “”"" + fbIdUnique("${facebookID}") + “”""}}"""))
    .check(status.is(201), jsonPath("$.accessToken").saveAs(“access_token”)))

//Return unique email base on timestamp
def emailUnique(email: String): String = {
var emailUnique = “testGatling” + “+” + System.currentTimeMillis + “@example.com
return emailUnique
}

OK, so that will never work. read this: https://github.com/excilys/gatling/blob/master/src/sphinx/session/expression_el.rst

One solution would be:

val provisioning =feed(provisioningUsers)

.exec(session => session.set(“email”, emailUnique(session(“login”).as[String]))

.body(StringBody("""{“login”: “${email}”, “password”: “${password}”, …

Same thing goes with fbIdUnique.

Thanx you very much ! It works ! :slight_smile:

I found this old post related answer: https://groups.google.com/forum/#!msg/gatling/ycR9LtoU1_c/eoJDXyQ-BgUJ