Last active
August 20, 2020 12:14
-
-
Save pbezpal/50c5cda370c4e1b49515dae109bfb55b to your computer and use it in GitHub Desktop.
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
import BasicLoad.start | |
import Requests.usersLogin | |
import io.gatling.core.ConfigKeys.socket | |
import io.gatling.core.Predef._ | |
import io.gatling.http.Predef._ | |
import io.gatling.core.scenario.Simulation | |
import io.gatling.jsonpath | |
import io.socket.client.{IO, Socket} | |
import io.socket.emitter.Emitter | |
import io.socket.emitter.Emitter.Listener | |
import org.json.JSONObject | |
import scala.concurrent.duration._ | |
import scala.language.postfixOps | |
class ServerLoad extends Simulation{ | |
val port = Integer.getInteger("port", 8080) | |
val host = System.getProperty("host", "localhost") | |
val wsUrl = "wss://$host:$port/socket.io/?EIO=3&transport=websocket&sid=" + "${sessionId}" | |
val socketUrl = "https://testing.ros.chat:8080" | |
val optConnect = new IO.Options() | |
val users = csv("./users.csv") | |
.circular | |
val httpConf = http.baseUrl("https://localhost") | |
/*.userAgentHeader("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) " + | |
"Chrome/81.0.4044.138 YaBrowser/20.4.3.268 (beta) Yowser/2.5 Safari/537.36")*/ | |
.wsBaseUrl("wss://localhost:8080") | |
val scn = scenario("UsersLogin").feed(users).during(10 second){ | |
//exec(usersLogin) | |
exec(ws("Connect").connect("/socket.io/?EIO=3&transport=websocket").headers( | |
Map( | |
"User-Agent" -> "${device}" | |
) | |
) | |
) | |
.pause(1) | |
.exec(session => { | |
optConnect.forceNew = false | |
optConnect.timeout = 10000 | |
val obj = new JSONObject() | |
obj.put("login", "${login}") | |
obj.put("password", "${password}") | |
obj.put("APILevel", "${level}") | |
val socket = IO.socket( socketUrl, optConnect ) | |
socket.connect() | |
socket.on( Socket.EVENT_CONNECT, new Listener { | |
override def call(args: Any*): Unit = { //This error | |
socket.emit("login", obj) | |
} | |
} | |
) | |
} | |
) | |
.exec(ws("Close connect").close) | |
} | |
setUp(scn.inject(rampUsers(1) during(5 second)). | |
protocols(httpConf)) | |
.maxDuration(15 second) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment