forked from tinode/chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loadtest: add me and single (group) topic loadtest scenarios.
- Loading branch information
aforge
committed
Mar 2, 2021
1 parent
92fc284
commit 995c706
Showing
2 changed files
with
229 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package tinode | ||
|
||
import java.util.Base64 | ||
import java.util.concurrent.ConcurrentHashMap | ||
|
||
import scala.collection.JavaConverters._ | ||
import scala.collection._ | ||
import scala.concurrent.duration._ | ||
|
||
import io.gatling.core.Predef._ | ||
import io.gatling.http.Predef._ | ||
|
||
class TinodeBase extends Simulation { | ||
val httpProtocol = http | ||
.baseUrl("http://localhost:6060") | ||
.wsBaseUrl("ws://localhost:6060") | ||
|
||
// Auth tokens to share between sessions. | ||
val tokenCache : concurrent.Map[String, String] = new ConcurrentHashMap() asScala | ||
|
||
val hello = exitBlockOnFail { | ||
exec { | ||
ws("hi").sendText( | ||
"""{"hi":{"id":"afabb3","ver":"0.16","ua":"Gatling-Loadtest/1.0; gatling/1.7.0"}}""" | ||
) | ||
.await(15 seconds)( | ||
ws.checkTextMessage("hi") | ||
.matching(jsonPath("$.ctrl").find.exists) | ||
) | ||
} | ||
} | ||
|
||
val loginBasic = exitBlockOnFail { | ||
exec { session => | ||
val uname = session("username").as[String] | ||
val password = session("password").as[String] | ||
val secret = new String(java.util.Base64.getEncoder.encode((uname + ":" + password).getBytes())) | ||
session.set("secret", secret) | ||
} | ||
.exec { | ||
ws("login").sendText( | ||
"""{"login":{"id":"${id}-login","scheme":"basic","secret":"${secret}"}}""" | ||
) | ||
.await(15 seconds)( | ||
ws.checkTextMessage("login-ctrl") | ||
.matching(jsonPath("$.ctrl").find.exists) | ||
.check(jsonPath("$.ctrl.params.token").saveAs("token")) | ||
) | ||
} | ||
.exec { session => | ||
val uname = session("username").as[String] | ||
val token = session("token").as[String] | ||
tokenCache.put(uname, token) | ||
session | ||
} | ||
} | ||
|
||
val loginToken = exitBlockOnFail { | ||
exec { session => | ||
val uname = session("username").as[String] | ||
var token = session("token").asOption[String] | ||
if (token == None) { | ||
token = tokenCache.get(uname) | ||
} | ||
session.set("token", token.getOrElse("")) | ||
} | ||
.exec { | ||
ws("login-token").sendText( | ||
"""{"login":{"id":"${id}-login2","scheme":"token","secret":"${token}"}}""" | ||
) | ||
.await(15 seconds)( | ||
ws.checkTextMessage("login-ctrl") | ||
.matching(jsonPath("$.ctrl").find.exists) | ||
) | ||
} | ||
} | ||
|
||
val subMe = exitBlockOnFail { | ||
exec { | ||
ws("sub-me").sendText( | ||
"""{"sub":{"id":"${id}-sub-me","topic":"me","get":{"what":"desc"}}}""" | ||
) | ||
.await(15 seconds)( | ||
ws.checkTextMessage("sub-me-desc") | ||
.matching(jsonPath("$.ctrl").find.exists) | ||
.check(jsonPath("$.ctrl.code").ofType[Int].in(200 to 299)) | ||
) | ||
} | ||
} | ||
|
||
val subTopic = exitBlockOnFail { | ||
exec { | ||
ws("sub-topic").sendText( | ||
"""{"sub":{"id":"${id}-sub-${sub}","topic":"${sub}","get":{"what":"desc sub data del"}}}""" | ||
) | ||
.await(15 seconds)( | ||
ws.checkTextMessage("sub-topic-ctrl") | ||
.matching(jsonPath("$.ctrl").find.exists) | ||
.check(jsonPath("$.ctrl.code").ofType[Int].in(200 to 299)) | ||
) | ||
} | ||
} | ||
|
||
val publish = exitBlockOnFail { | ||
exec { | ||
repeat(3, "i") { | ||
exec { | ||
ws("pub-topic").sendText( | ||
"""{"pub":{"id":"${id}-pub-${sub}-${i}","topic":"${sub}","content":"This is a Tsung test ${i}"}}""" | ||
) | ||
.await(15 seconds)( | ||
ws.checkTextMessage("pub-topic-ctrl") | ||
.matching(jsonPath("$.ctrl").find.exists) | ||
.check(jsonPath("$.ctrl.code").ofType[Int].in(200 to 299)) | ||
) | ||
} | ||
.pause(0, 3) | ||
} | ||
} | ||
} | ||
|
||
val getSubs = exitBlockOnFail { | ||
exec { | ||
ws("get-subs").sendText( | ||
"""{"get":{"id":"${id}-get-subs","topic":"me","what":"sub"}}""" | ||
) | ||
.await(15 seconds)( | ||
ws.checkTextMessage("save-subs") | ||
.matching(jsonPath("$.meta.sub").find.exists) | ||
.check(jsonPath("$.meta.sub[*].topic").findAll.saveAs("subs")) | ||
) | ||
} | ||
} | ||
|
||
val leaveTopic = exitBlockOnFail { | ||
exec { | ||
ws("leave-topic").sendText( | ||
"""{"leave":{"id":"${id}-leave-${sub}","topic":"${sub}"}}""" | ||
) | ||
.await(15 seconds)( | ||
ws.checkTextMessage("sub-topic-ctrl") | ||
.matching(jsonPath("$.ctrl").find.exists) | ||
) | ||
} | ||
} | ||
} |