# MULTIPLE users in same scenario

**URL:** <https://community.gatling.io/t/multiple-users-in-same-scenario/5698>\
**Category:** Gatling (Open-Source)\
**Created:** [July 3, 2020, 7:53pm UTC](https://community.gatling.io/t/multiple-users-in-same-scenario/5698 "2020-07-03T19:53:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Snow\_Man](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@Snow\_Man](https://community.gatling.io/u/Snow_Man)\
**Post date:** [July 3, 2020, 7:53pm UTC](https://community.gatling.io/t/multiple-users-in-same-scenario/5698/1 "2020-07-03T19:53:30Z")

</div>

My requirement is like one user logs in create somethimg and then other user logs in and updates it.

Feeder is csv as below

User1, user2  
1001,4001  
1002,4002  
1003,4003

Val createProduct =

exec(http("login")  
.post("/login")  
.formparam("user","${user1}")  
.formparam("pwd","5656666"))

.exec{session=\>  
getCookievalue(CookieKey(XSRF-TOKEN)).saveAs("XSRF-TOKEN")  
}

.exec(http("create")  
.post("/create")  
.header("x-xsrf-token","${XSRF-TOKEN}"  
.body())

.exec(http("logout")  
.get("logout"))

.exec(http("login2")  
.post("/login")  
.formparam("user","${user2}")  
.formparam("pwd","5656666"))

.exec{session=\>  
getCookievalue(CookieKey(XSRF-TOKEN)).saveAs("XSRF-TOKEN")  
}

.exec(http("update")  
.post("/update")  
.header("x-xsrf-token",getCookievalue(CookieKey(XSRF-TOKEN))  
.body())

.exec(http("logout")  
.get("logout"))

Val scenario= Scenario("test").feed(feeder)  
.exec(createProduct)

Setup(scenario.inject(rampusers(8) during(10 seconds))

Ignore any typos.

My issue is when the second user logs in and tries to update the product, its getting the XSRF-TOKEN same as from the first user session.

Is there anything i am missing here.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [July 3, 2020, 8:00pm UTC](https://community.gatling.io/t/multiple-users-in-same-scenario/5698/2 "2020-07-03T20:00:58Z")

</div>

Maybe because you’re fighting against the way Gatling’s virtual users work and using the same virtual user for 2 different “actual” users.  
Each Gatling virtual user has its own CookieJar. There’s a good chance your second authentication is ineffective because there’s already a valid cookie.

Try flushing the CookieJar in between: [https://gatling.io/docs/current/http/http\_helpers/#flushing-all-cookies](https://gatling.io/docs/current/http/http_helpers/#flushing-all-cookies)

Again, enabling DEBUG logging would help you see what happens on the wire.

---

<div class="post-metadata">

**Author:** ![Snow\_Man](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@Snow\_Man](https://community.gatling.io/u/Snow_Man)\
**Post date:** [July 4, 2020, 11:00pm UTC](https://community.gatling.io/t/multiple-users-in-same-scenario/5698/3 "2020-07-04T23:00:54Z")

</div>

hi Stephane,

Tried flushing cookies and cache after the first user logs out, but still its not working.

Any other options pls.

Thanks

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [July 5, 2020, 10:05am UTC](https://community.gatling.io/t/multiple-users-in-same-scenario/5698/4 "2020-07-05T10:05:44Z")

</div>

I’m positive the issue isn’t with Gatling but either with your test or your application.  
Can’t do more than this, as I pointed out, you should lower logging level and start debugging what happens on the wire.
